Hi ppl,
Ive been trying to work how to get this done, and im starting to think my table structure is not correct to allow the query im trying to acheive.
Anyway heres an outline of the tables and the result i want
Table1: contact
Id firstname lastname
1 mark little
2 burt bertie
Table2: contact_data
contact_id data_field_id data
1 1 Vodka
1 2 Apples
Table3: contact_data_field
data_field_id field
1 Favourite Drink
2 Favourite Fruit
I want to return all contacts whos Favourite drink is vodka AND whos favourite fruit is Apples.
I can get the result for OR by using
select contact.id,contact.firstname,contact.lastname from contact
left join contact_data on contact.id = contact_data.contact_id where
(contact_data.data_field_id="1" and contact_data.data like "vodka") or
(contact_data.data_field_id="2" and contact_data.data like "apples")
But I dont get any results when I use AND when I should get the contact with ID 1.
Any help will be appreciated.
Mark.