Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql Sql选择不存在的记录?_Mysql_Sql_Oracle_Oracle11g_Oracle Sqldeveloper - Fatal编程技术网

Mysql Sql选择不存在的记录?

Mysql Sql选择不存在的记录?,mysql,sql,oracle,oracle11g,oracle-sqldeveloper,Mysql,Sql,Oracle,Oracle11g,Oracle Sqldeveloper,我正在尝试将以下3个查询修改为一个具有最终输出的查询 第一个查询返回ID和位置的列表 Select id,place from Global where status='Y'; 查询示例输出:- 1) 德里123号 select * from global g where not exists (select 1 from Licence l where l.licenceId=g.id and l.state='MO') and not exists (select 1 from Drvin

我正在尝试将以下3个查询修改为一个具有最终输出的查询

第一个查询返回ID和位置的列表

Select id,place from Global where status='Y';
查询示例输出:-

1) 德里123号

select * from global g
where not exists (select 1 from Licence l where l.licenceId=g.id and l.state='MO')
and not exists (select 1 from DrvingLicence dl where dl.drivingLicenceNo=g.id and dob=to_date('12121978','ddmmyyyy'))
2) 查谟345

3) 哈里亚纳邦456号

然后我想把这个输出发送到

要筛选的许可证和DRVINGLICENSE表,如果此表中出现id,则从最终输出中排除该id

LicenseID=id和DrivingLicenseNo=id

Select licenceId from Licence table where state='MO' and licenceid=:id
Select drivingLicenceNo from DrvingLicence table where DOB='12/12/1978' and drivingLicenceNo=:id
位置仅出现在应出现在最终输出中的“全局”表中

最终输出:

1) 德里123号

select * from global g
where not exists (select 1 from Licence l where l.licenceId=g.id and l.state='MO')
and not exists (select 1 from DrvingLicence dl where dl.drivingLicenceNo=g.id and dob=to_date('12121978','ddmmyyyy'))
假设许可证表中存在id=345,而DrvingLicense表中存在id=456,请尝试此操作

select 
    id,
    place 
from Global g
where status='Y'
and NOT EXISTS (
    select
        licenceId
    from Licence l
    on g.id = l.licenceId
)
OR NOT EXISTS (
    select
        drivingLicenceNo
    from DrvingLicence dl
    on g.id = dl.drivingLicenceNo
);
也许使用一些连接

Select g.id,g.place 
  from Global g 
      INNER JOIN Licence li ON g.id != li.id 
      INNER JOIN DrvingLicence dl ON g.id != dl.id 
 WHERE g.status='Y' 
   AND li.state='MO' 
   AND dl.DOB='12/12/1978';

你能试试这个吗,它对我很管用。最终产量为123,德里

select * from global g
where not exists (select 1 from Licence l where l.licenceId=g.id and l.state='MO')
and not exists (select 1 from DrvingLicence dl where dl.drivingLicenceNo=g.id and dob=to_date('12121978','ddmmyyyy'))
试试这个吧

SELECT * FROM GLOBAL g
WHERE g.id NOT IN (Select licenceId from Licence table where state='MO',Select drivingLicenceNo from DrvingLicence table where DOB='12/12/1978')

希望它能起作用。

你好!欢迎来到SO。下次尝试格式化你的答案(这次我帮你做了,只需查看编辑页面并查看一下)。您只需要在代码前添加一个空行(无论是什么形式的文本),并在每行代码前添加四个空格或一个制表符。希望你们喜欢。很抱歉,这仍然是许可证表中的一个记录。可能使用另一个答案,但不使用或放置AND,而不是子查询中的ON,它在何处返回唯一记录?如果记录出现在两个表中,它将如何运行?@nightwawk您应该尝试运行它。抱歉,出现语法错误,您的SQL语法中有错误;错误似乎围绕着:“on g.id=l.licenceId)或不存在(在第12行选择drivingLicenceNo”,其到期日期为“on”。但查询仍返回存在于其他表中的记录。您使用的是MySQL还是Oracle?一些示例表数据和预期结果会有所帮助-都是格式化文本,而不是图像。()