Jump to content

select statement from two tables


sandy1028

Recommended Posts

I have to 3 tables Table1,table2,table3 and in all tables field name  `fieldname` is similar .

 

I have to select values from table1 the values which is not in table2 and table3.

 

Select  distinct(fieldname) from table1 where fieldname not in (select distinct(fieldname) from table2 union (select distinct(fieldname) from table3)

 

 

But I am gtting the proper result

Link to comment
https://forums.phpfreaks.com/topic/94132-select-statement-from-two-tables/
Share on other sites

I'm curious to know the database layout as it would seem that the tables aren't normalised at first glance.

 

SELECT t1.fieldname 
FROM table1 t1
LEFT JOIN table2 t2 ON t1.fieldname = t2.fieldname
LEFT JOIN table3 t3 ON t1.fieldname = t3.fieldname
WHERE t2.fieldname IS NULL
OR t3.fieldname IS NULL

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.