2013-02-20 47 views
0

我有一個關於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 
+2

通過使用ID爲'0的'exp_channel_titles.entry_id'? – h2ooooooo 2013-02-20 10:35:07

回答

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 
+0

當我這樣做時,什麼都沒有出來。甚至沒有我的restaurant_id> 0 – Zaz 2013-02-20 10:44:14

1

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

2

你可以做到這一點通過

WHERE t.cardid > 0 OR t.restaurant_id=0 

如果CardId中比0刨絲器不是強制性的,你也可以使用,並確保該t.cardid也大於0

+0

當我這樣做時,什麼都沒有出來。甚至沒有我的restaurant_id> 0 – Zaz 2013-02-20 10:44:36

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


    ?> 
+0

當我這樣做時,什麼都沒有出來。甚至沒有我的restaurant_id> 0 – Zaz 2013-02-20 10:44:56