I am using LAMP. In MySql I have a table with columns X, Y and Z. I need to select distinct records from multiple sets and subsets. If my initial criteria is WHERE Y = A; then I need to be able to:
The table could get quite large and I'm not really sure where to start with this. Some possible approaches would be to:
I am leaning toward option number 4, but not 100% sure. Am I reinventing the wheel?
Much appreciated...
I do not understand your goal because you haven't defined a restriction on X, however from your description I believe that set E would be empty. I say this because set D already contains rows where Z is 456. So when you run another query on that resultset to generate E for the condition where Z is 789, you will not get any rows back because all the rows in D are 456.
Now to personal opinions:
In order to highlight item #4 above, I would like to mention that in your example for D, you can write the following query without subqueries or any other temporary storage:
SELECT * FROM MyTable WHERE Y = A AND Z = 456
Now, maybe I can attempt to solve your dilemma by guessing what you want:
SELECT * FROM MyTable WHERE Y = A AND Z IN (123, 456, 789)
Or:
SELECT * FROM MyTable WHERE Y = A AND (Z = 123 OR Z = 456 OR Z = 789)
Hope this helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.