我有一個關於SQL語句的問題。我如何在我的SQL語句中執行此操作
此SQL語句正常工作,但我也想找到Restarurant_ID
中有0的餐館。我怎麼能在這個聲明中做到這一點?
SELECT ct.*, t.*
FROM exp_channel_titles AS ct
LEFT JOIN transactions AS t ON (ct.entry_id = t.restaurant_id)
WHERE t.cardid > 0
ORDER BY t.created DESC
我有一個關於SQL語句的問題。我如何在我的SQL語句中執行此操作
此SQL語句正常工作,但我也想找到Restarurant_ID
中有0的餐館。我怎麼能在這個聲明中做到這一點?
SELECT ct.*, t.*
FROM exp_channel_titles AS ct
LEFT JOIN transactions AS t ON (ct.entry_id = t.restaurant_id)
WHERE t.cardid > 0
ORDER BY t.created DESC
SELECT
ct.*, t.*
FROM
exp_channel_titles as ct
LEFT JOIN
transactions as t on (ct.entry_id = t.restaurant_id)
WHERE
t.cardid > 0 and t.restaurant_id=0
order by t.created DESC
當我這樣做時,什麼都沒有出來。甚至沒有我的restaurant_id> 0 – Zaz 2013-02-20 10:44:14
添加AND restaurant_id = 0
到您的where子句
你可以做到這一點通過
WHERE t.cardid > 0 OR t.restaurant_id=0
如果CardId中比0刨絲器不是強制性的,你也可以使用,並確保該t.cardid
也大於0
當我這樣做時,什麼都沒有出來。甚至沒有我的restaurant_id> 0 – Zaz 2013-02-20 10:44:36
在PHP:
<?php
$result = mysql_query("SELECT
ct.*, t.*
FROM
exp_channel_titles as ct
LEFT JOIN
transactions as t on (ct.entry_id = t.restaurant_id)
WHERE
t.cardid > 0 and t.restaurant_id=0
order by t.created DESC");
while($row = mysql_fetch_array($result)){
echo $row['field'];
}
?>
當我這樣做時,什麼都沒有出來。甚至沒有我的restaurant_id> 0 – Zaz 2013-02-20 10:44:56
通過使用ID爲'0的'exp_channel_titles.entry_id'? – h2ooooooo 2013-02-20 10:35:07