How to wr开发者_运维知识库ite AND
query instead of using VALUE IN
?
I need to get exact results:This is master table
id name value
1 weight 120
2 height 5
3 active true
4 age 35
I should get ids when (weight 120 AND height 5 AND age 35) . And should not get results when (weight 120 AND height 5 AND age 100)
Any Help
thanks
Try
SELECT * FROM table WHERE name='one' OR name='two'
OR try
SELECT * FROM table WHERE id=1 OR id=2
Easy one:
SELECT * FROM table
WHERE `name` IN ('one', 'two') AND `value` BETWEEN 1 AND 2;
I hope I got you right.
Update
Completly without IN
it would look like the following query:
SELECT * FROM table
WHERE (`name` = 'one' OR `name` = 'two') AND `value` BETWEEN 1 AND 2;
Update 2
If you are looking for pairs:
SELECT * FROM table
WHERE (`name` = 'one' AND `value` = '1') OR (`name` = 'two' AND `value` = '2');
Update 3
... and additionally active:
SELECT * FROM table
WHERE ((`name` = 'one' AND `value` = '1') OR (`name` = 'two' AND `value` = '2'))
AND `active` = true;
Looks like bad database design though. Maybe you can give us further insight about what you are trying to do.
精彩评论