Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In mysql i have records as



hotelid amenitieid
31534 719
31534 665
31534 603
31534 663
31534 1993
31534 638
31124 719
14744 719
25363 665
12523 603
17458 665


and want hotelid where amenitieid=719 and amenitieid=603 (both are there)
from above database field values

what is mysql query for this
Posted
Comments
thatraja 2-Jan-14 4:23am    
what have you tried?
maulikshah1990 2-Jan-14 4:24am    
I tried as

SELECT *
FROM `amenities`
where amenitieid = '719' AND amenitieid = '603'

Try:
SQL
SELECT * FROM MyTable WHERE amenitieid=719 OR amenitieid=603


[edit]Typo - AND for OR[/edit]
 
Share this answer
 
v2
Comments
maulikshah1990 2-Jan-14 4:24am    
i tried ..and but not working
OriginalGriff 2-Jan-14 4:53am    
Show exactly what you tried - copy and paste from your source the relevent fragment with a couple of lines either side for context.
maulikshah1990 2-Jan-14 4:54am    
SELECT *
FROM `amenities`
where amenitieid = '719' AND amenitieid = '603'
OriginalGriff 2-Jan-14 5:10am    
First remove the quotes around the table name - you don't need them.
Then change AND to OR.
AND requires both conditions to be true, and since they are both working on the same column, it can't be two different values at the same time. OR requires one or the other condition to be true, so it will returns rows where the value matches either value
maulikshah1990 2-Jan-14 5:15am    
hotelid amenitieid
31534 719
31534 665
31534 603
31534 663
31534 1993
31534 638
31124 719
14744 719
25363 665
12523 603
17458 665


In the above , i want
hotelid where amenitieid = '719' and hotelid='665' ..and there is record hotelid with both amenities like 31534 ,

pls give mysql query for this..
You could add a de-normalized table, having the hotelid and a boolean column for each amenityid, and perform the search in that table.
But then make sure that that table is updated automatically when the data in the original tables change (e.g. using triggers).
 
Share this answer
 
Comments
maulikshah1990 3-Jan-14 5:40am    
give example for above records i have posted..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900