Wednesday, October 22, 2014

Nested select statement for MySQL db

Here is a example of how to create nested sql statement that indicate with a value is in the list.

SELECT distinct userid from IPSOS where userid in (SELECT distinct otxid from Mag0_20141021) and userid in (SELECT distinct id from Mag1_20141021) and userid in (SELECT distinct id from Mag2_20141021) and userid in (SELECT distinct id from Mag3_20141021) and userid not in (SELECT distinct otxid from problem) 

Notice the where in and where not in and how userid gets compared to the out come of the next select statement

No comments:

Post a Comment