当前位置: 代码迷 >> PHP >> 搜索A表在B表里没有数据的记录如何写SQL语句
  详细解决方案

搜索A表在B表里没有数据的记录如何写SQL语句

热度:363   发布时间:2016-04-28 18:51:33.0
搜索A表在B表里没有数据的记录怎么写SQL语句?
如:
A表
a_id       name   ........
   1         张三
  2         李四
  3         王五
  4         赵六


B表
b_id        a_id        total
1             1           100
2             3           200

<form method="post" name="frm" id="frm" action="?act=list">
<input name="qianfei" id="qianfei" value="1" type="checkbox" {if $qianfei gt '0'}checked="checked"{/if} /> 欠费
<input name="sou" type="button" class="ann10" value="" onclick="s_xueyuan()" />
</form>
勾选上面的欠费提交后怎么搜索出李四和赵六????
------解决方案--------------------
因為王五有交費,且沒有欠費,所以不用顯示。
樓主應該是要找出未交費或有欠費的用戶

select t1.name from a as t1 left join b as t2 on t1.a_id=t2.a_id where qianfei is null or qianfei>0;

可以這樣寫,先left join,然後找出qianfei>0 或 qianfei為null的記錄即可。
  相关解决方案