Select data that is not match data in another table in MySQL

13 Oct

We have mock up data in both table as below:

ID Name
1 Mr. A
2 Ms. B
3 Mrs. C


ID Table1ID Name
1 3 ABC Beer
2 1 Tiger Beer

And we want to select data in table1 that is not avaiable in table2, so when you want to do as I said.

You should use:

SELECT table1.*

FORM table1 LEFT JOIN table2 ON table1.ID = table2.Table1ID

WHERE table2.Table1ID is null



ID Name
2 Ms. B
Leave a comment

Posted by on October 13, 2009 in MySQL Server


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: