我有一個很長的SQL語句,我試圖添加一些AND條件,但它不工作。SQL選擇多個和
這裏是我的發言:
if($cat=="att") { $sqlCatC = "INNER JOIN yt_att_data CAT
ON CAT.busID = R.id AND CAT.subcatID = 5 AND CAT.subcatID = 136 AND CAT.deleted = 0"; }
//Get RegionInfo busID based on region, approved
$sql= "SELECT DISTINCT CAT.busID,R.id,companyName,membershipID,addressID,city,logo,descriptionShort FROM yt_Business_RegInfo R
$sqlReg
INNER JOIN yt_Business_Seasons S
ON R.id = S.busID AND S.deleted = 0
INNER JOIN yt_Business_Address A
ON R.addressID = A.id
INNER JOIN yt_Business_Membership M
ON R.membershipID = M.id AND M.approved = 1
$sqlCatC
WHERE R.deleted = 0
ORDER BY R.companyName ASC LIMIT $start, $limit";
它在頂部$ sqlCatC,我試圖添加一個與其中CAT.subcatID等於5和136條件下它的工作原理與檢查一單個CAT.subcatID但不是兩個。任何建議,將不勝感激。
對於單個行'CAT.subcatID'不能同時是'5'和'136'。你需要'OR'嗎?還是你正在尋找[關係部門](http://www.simple-talk.com/sql/t-sql-programming/divided-we-stand-the-sql-of-relational- (在這種情況下,你需要'OR','GROUP BY'和'HAVING')? – 2011-04-13 17:25:15
它不起作用?你有錯誤嗎?還是錯誤的結果?如果是這樣,結果如何?我懷疑你可能想要一個OR而不是AND。 – driis 2011-04-13 17:25:53
如果我使用OR,那麼它只會顯示具有所選子代碼5或136的記錄。我需要它顯示已選擇的公司記錄。這基本上是一個公司記錄,有一定的標準檢查,如果這兩個都被檢查,我需要顯示它。 – Paul 2011-04-13 18:23:44