Re: SQL query to return all matching condition
Hi Faheed,
What do you mean by a "record"? To me, it is synonymous to a "row". You seem to aim at "all rows with the same value for the name field" as a definition for a record.
At least, I conclude this rereading your original wish:
> I just want to pickup the records that matches both the categories "cat1" and "cat2"
Well, clearly there are no rows that match both categories at once. Each row has only one category field, and the value of the category field of a particular row cannot be and 'cat1' and 'cat2' at the same time.
So, judging from your desired result, you must mean that all rows with the 'aaa' value for the name field are one record (two rows, one cat1 and one cat2). Same for all rows with the 'bbb' value for the name field.
Is this correct? If so, either one way or the other, you will have to tell MySQL that you don't just mean all records which happen to have a category 'cat1' and 'cat2', but only those records that also have the 'aaa' value in the name field.
And this is exactly what my two suggestions do.