Well, here's a fix to your code:
SELECT table.name FROM `table` LEFT JOIN table2 ON table.name=table2.name2 WHERE table2.name2 IS NULL ORDER BY table.name ASC
Now, you will have to change the column title in one of the tables (in this case table 2). That query works fine, except it returns 28 entries.
Why does it return 28 entries you ask?
Well there are 8 entries in table 1, and 4 entries in table 2. 8*4 = 32. 4 of the entries in table 1 are in table 2. 32-4 = 28.
What this query is doing is comparing EACH name in table 1 to EACH name in table 2. So, there will be 8 tries per each name.
I don't possess theknowledge to refine the query so that it only checks each item once. Someone else can help you with that.
You can see the following script in action here:
Viewable Here
Just click on Join 2 Tables.
Code will be printed below output.
<?php
$dbc = mysql_connect("localhost", "db_user", "******");
mysql_select_db("database", $dbc);
$query = "SELECT table.name FROM `table` LEFT JOIN table2 ON table.name=table2.name2 WHERE table2.name2 IS NULL ORDER BY table.name ASC";
$result = mysql_query($query) or die('ERROR: Query failed:<br><i>'.$query.'</i><br><b>'.mysql_errno().'</b><br>'.mysql_error());
echo '<h2>Missing Names</h2>';
while($names = mysql_fetch_array($result)){
echo($names['name'].'<br>'."\n");
}
?>
~Brett