我想显示没有or_cancelled 0的ref_number谢谢

时间:2016-06-28 09:06:20

标签: php

我有两个表tbl_particular,tbl_collection

android:windowSoftInputMode="stateHidden|adjustPan"

假设没有输出,因为DISCO-X-2016-0162的or_cancelled为0。

需要帮助

2 个答案:

答案 0 :(得分:0)

使用以下查询获得预期输出

SELECT DISTINCT tbl_particular.ref_number AS data1,
                 tbl_particular.or_number AS data2
                 FROM tbl_collection , tbl_particular 
                WHERE tbl_particular.or_number=tbl_collection.or_number and tbl_particular.ref_number NOT IN (SELECT DISTINCT ref_number FROM tbl_collection where or_cancelled =0 ) 

说明:

sub query : 
(SELECT DISTINCT ref_number FROM tbl_collection where or_cancelled =0 )  will give list of ref_numbers which is having or_cancelled =0

main query :
  SELECT DISTINCT tbl_particular.ref_number AS data1,
             tbl_particular.or_number AS data2
             FROM tbl_collection , tbl_particular 
            WHERE tbl_particular.or_number=tbl_collection.or_number and tbl_particular.ref_number NOT IN (result of sub query) 

will give other then sub query resulted ref_numbers so you will get empty result set

预期产出:

empty result set

答案 1 :(得分:0)

试用此代码

SELECT
 tbl_particular.ref_number,
 tbl_particular.or_number
FROM tbl_particular
INNER JOIN tbl_collection
 ON tbl_particular.or_number=tbl_collection.or_number
WHERE tbl_collection.ref_number NOT IN (
 SELECT ref_number FROM tbl_collection WHERE or_cancelled = 1 GROUP BY ref_number
);