Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sql query for retrieving data using join condition.
shown bellow are the two tables.

Table1                                      Table2                             
      Eid Packet                               Eid Packet    
108020002000012013                 108020002000012013 
108020002000022013                 108020002000022013
108020002000032013                 108020002000052013
108020002000042013                 108020002000062013
108020002000052013                 108020002000072013
108020002000062013                 108020002000102013
108020002000072013                 108020002000112013
108020002000082013                
108020002000092013      

i want o/p like bellow.data retrieving based on underline value.

two tables                  1st table un
matched records           Matched records           2nd table un Matched
                                                                                                       
108020002000012013      108020002000032013         108020002000102013
108020002000022013      108020002000042013         108020002000112013
108020002000052013      108020002000082013   
108020002000062013
108020002000072013
Posted
v2
Comments
chaau 5-Jun-13 2:17am    
What have you tried? Hint: for fully matched you would use INNER JOIN, for unmatched you would use LEFT/RIGHT JOINs.
To compare using part of the strings you would use SUBSTRING.
Show us some code that you have written yourself, and we will help you
subbu a 5-Jun-13 2:30am    
SELECTtable1.EidPacket
FROM table1, table2
WHERE Ttable1.EidPacket =Ttable1.EidPacket


i am not getting exactly ans. how can i retrieving based on middle value in the record.
Maciej Los 6-Jun-13 1:54am    
Is your problem solved?

1 solution

Exact match:
SQL
SELECT t1.EidPocket
FROM table1 AS t1 INNER JOIN table2 AS t2 ON t1.EidPacket = t2.EidPocket


Non-matches:
SQL
SELECT EidPocket
FROM table1 AS t1 
WHERE EidPocket NOT IN (SELECT t2.EidPocket
            FROM table1 AS t1 INNER JOIN table2 AS t2 ON t1.EidPacket = t2.EidPocket)


Morea about:
Join's[^]
Visual Representation of SQL Joins[^]
 
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