查询以从同一数据库的两个表中选择不同的记录 [英] query to select distinct records from two tables from same data base

查看:70
本文介绍了查询以从同一数据库的两个表中选择不同的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TABLE_A

TABLE_A

AUTO_ID IMEI LATITUDE LONGITUDE TIME_STAMP

1        111  19.77    18.88      2:00:00
2        111  19.77    18.88      2:20:00
3        111  19.77    18.88      2:30:00


TABLE_B


TABLE_B

AUTO_ID IMEI LATITUDE LONGITUDE TIME_STAMP

1        111  19.77    18.88      2:00:00
2        111  19.77    18.88      2:20:00
3        111  19.77    18.88      2:30:00
4        123  20.20    21.24      4:00:00



所以我需要查询才能仅选择该行(4 123 20.20 21.24 4:00:00)
从上面两个表中



So I need query to select only this row( 4 123 20.20 21.24 4:00:00)
from the above two tables

推荐答案

如果只想选择该行(4 123 20.20 21.24 4:00:00)
if you want to select only this row( 4 123 20.20 21.24 4:00:00)
select * from table_B where IMEI not in(Select IMEI from table_A)


您好...

首先,您要告诉您要从哪个表进行记录

确实要加入查询并在WHERE子句中采用条件,例如col1table1<> col1table2或col2table2<> col2table2 .........

尝试执行此查询,我假设您还有一个表TABLE_C具有相同结构AS table_b,

hi there...

first u tell from which table u wants records
or
do join query and take condition in WHERE clause like col1table1<> col1table2 OR col2table2 <> col2table2 .........

try this query,i m assuming u hve one more table TABLE_C WITH SAME STRUCTURE AS table_b,

INSERT INTO TABLE_C
SELECT distinct b.* FROM TABLE_B b ,TABLE_A a
WHERE b.IMEI NOT IN(SELECT a.IMEI FROM TABLE_A a)
OR
(b.IMEI=a.IMEI AND (b.LATITUDE<>a.LATITUDE OR b.LONGITUDE<>a.LONGITUDE))








希望这会有所帮助..
回复您的评论...








hope this helps..
revert back with ur comments...




Distinct关键字用于显示不同的记录,但请确保您在必须在select查询中的字段上使用order by或group by子句.
Hi,

Distinct keyword is used to displays different records but make sure you are using order by or group by clause for the on the field that must be in the select query.


这篇关于查询以从同一数据库的两个表中选择不同的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆