我怎样才能在我的SQL语句中执行此操作

时间:2013-02-20 10:33:55

标签: 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

4 个答案:

答案 0 :(得分:2)

你可以通过

来做到这一点
WHERE t.cardid > 0 OR t.restaurant_id=0 

如果卡的强制要求不大于0,您也可以使用AND来确保t.cardid也大于0

答案 1 :(得分:1)

AND restaurant_id = 0添加到您的where子句

答案 2 :(得分:1)

在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'];
        }


    ?>

答案 3 :(得分: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 and t.restaurant_id=0
order by t.created DESC