Need help for a specific SELECT statement
I need help. I have to do a very specific SQL Statement and I just can't figure out, how it should work.
What I got is two tables:
TABLE1: shop_articles CONTAINS pos (int), manufacturer (varchar)
TABLE2: shop_texts CONTAINS pos (int), text (text)
So I got two Variables $keyManufacturer
and $keyText
What I want is a intersection where $keyManufacturer
matches 'manufacturer' and check, if on the same 'pos' 'text' matc开发者_StackOverflowhes $keyText
I'm pretty sure, that's not too hard, but I can't figure out the solution. Any help?
SELECT `pos` FROM `shop_artciles` a, `shop_texts` b WHERE `a.manufacturer` =
'$keyManufacturer' AND `b.text` = '$ketText' AND `a.pos` = `b.pos`
Here there are 3 conditions in the WHERE
clause and the result is the rows that match all three conditions. Think this is what you want. You can try joins
in you are interested.
SELECT `a.pos` FROM `shop_artciles` AS a LEFT JOIN `shop_texts` AS b ON
`a.pos`= `b.pos` WHERE`a.manufacturer` = '$keyManufacturer'
AND `b.text` = '$ketText'
精彩评论