Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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

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


So I need query to select only this row( 4 123 20.20 21.24 4:00:00)
from the above two tables
Posted
Updated 1-Mar-12 20:10pm
v3
Comments
walterhevedeich 2-Mar-12 2:12am    
I don't see a reason why you need TABLE_A to get that row from TABLE_B. Won't SELECT * FROM TABLE_B WHERE AUTO_ID = 4 work?
Sergey Alexandrovich Kryukov 17-Jun-13 2:50am    
Please stop posting non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership. And the fact you even self-accepted some formally is just outrageous, a sure way for a ban. I hope you won't do it after this warning.

Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.
—SA

if you want to select only this row( 4 123 20.20 21.24 4:00:00)
SQL
select * from table_B where IMEI not in(Select IMEI from table_A)
 
Share this answer
 
Comments
kalyan10qwerty 2-Mar-12 3:09am    
i just gave you the sample table.i need to filter data from two table.for the above sample your query works fine:-) suppose if it gives same lat and long for the same imei then again issue raises
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,

SQL
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...
 
Share this answer
 
v3
Comments
kalyan10qwerty 2-Mar-12 3:12am    
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
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 24.20 21.24 4:10:00
5 124 25.20 22.24 4:20:00
6 125 26.20 23.24 4:30:00


I NEED TO SELECT DISTINCT RECORDS FROM THE ABOVE TO TABLES AND THE RESULTANT WILL BE STORED IN A NEW TABLE. NEED TOTAL ROW NOT A COLUMN
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.
 
Share this answer
 
we have a data base called raw data in which all the above formatted date will fall in to raw data data base.This data will come from a gprs device.so each unit consist of one gprs device.so all messages are date(what ever it may be) will b collected by one data base which contain each table for each device.so if a messages are date(what ever it may be) which consist of same latitude longitude timestamp etc etc will fall in to different tables so i need to filter the data and fill in to a new data base which consist of single table
 
Share this answer
 
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
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 24.20 21.24 4:10:00
5 124 25.20 22.24 4:20:00
6 125 26.20 23.24 4:30:00


I NEED TO SELECT DISTINCT RECORDS FROM THE ABOVE TO TABLES AND THE RESULTANT WILL BE STORED IN A NEW TABLE. NEED TOTAL ROW NOT A COLUMN
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900