我想列出一個查詢,如果兩種類型的產品在表中列出。 這是我在我的數據庫:MySQL重複查詢
表1
productID
productDescription
productYear
表2
porductID2
productDescription
productID (foreign Key from table1)
表1有:
01, Ball, 2001
02, Cone, 2002
03, Cube, 2010
表2具有
01, BallBaring, 01
02, LittleBall, 01
03, BallBaring, 02
04, LittleBall, 02
05, BallBaring, 03
我試圖只顯示包含BallBaring和LittleBall的結果。所以,當我搜索結果只顯示含有BallBaring和LittleBall結果:我有以下的搜索:
SELECT table2.productDescription, table1.productDescription, table2.productID2
FROM table1, table2
WHERE table1.productID = table2.productID2
AND (table2.productDescription = 'LittleBall'
OR table2.productDescription = 'BallBaring');
但這帶回有所有產品無論是BallBaring或LittleBall,而不是隻具有兩個BallBaring的那些和LittleBall,如果我這樣做,而不是或者它沒有帶回任何東西。
我似乎得到所有要麼LittleBall和BallBaring結果。所以我想要的結果是,BallBaring必須包含在Table1同時包含TableB中的BallBaring和LittleBall的結果中,希望您能理解。感謝您的快速響應。 – Dino 2013-03-12 14:14:32