我有一个关于 SQL 语句的问题。
此 SQL 语句工作正常,但我也想找到 0 中的餐馆Restarurant_ID
。我怎样才能在这个声明中做到这一点?
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 语句工作正常,但我也想找到 0 中的餐馆Restarurant_ID
。我怎样才能在这个声明中做到这一点?
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
你可以这样做
WHERE t.cardid > 0 OR t.restaurant_id=0
如果 cardid 不强制大于 0 ,您也可以使用 AND 确保t.cardid
也大于 0
添加AND restaurant_id = 0
到你的 where 子句
在 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'];
}
?>
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