If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Table joining

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-09-12, 00:58
vishnusivanpillai vishnusivanpillai is offline
Registered User
 
Join Date: Jan 2012
Posts: 1
Post Table joining

Hi,
Anyone can help me with this I have 2 table,
say

Table A
------------
id
---
1
2
3

Table B.
---------------
id name
------- ----------
1 saj
3 vnu
4 dad
1 saj
I want result as follow

id name
-------------------
1 saj
2
3 vnu

ie, result should contain all elements of A, corresponding field of B if it exist, Eliminate duplicate rows

Last edited by vishnusivanpillai; 01-09-12 at 01:01.
Reply With Quote
  #2 (permalink)  
Old 01-09-12, 01:14
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
This seems to be rather simple task. What did you manage to do so far? Please, post your query.
Reply With Quote
  #3 (permalink)  
Old 01-09-12, 02:31
gocool gocool is offline
Registered User
 
Join Date: Jan 2012
Posts: 5
select id,name from table A, table B where table A.id=table b.id;
Reply With Quote
  #4 (permalink)  
Old 01-09-12, 03:48
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,540
Quote:
Originally Posted by gocool View Post
select id,name from table A, table B where table A.id=table b.id;
nice try, but sorry, no cigar
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 01-09-12, 03:54
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,408
Quote:
Originally Posted by gocool View Post
select id,name from table A, table B where table A.id=table b.id;
Read up on outer joins
Reply With Quote
  #6 (permalink)  
Old 01-09-12, 04:13
gocool gocool is offline
Registered User
 
Join Date: Jan 2012
Posts: 5
Sorry guys, i am jus a beginner... Sorry fr the wrong info.. I thot i can give it a try...
Reply With Quote
  #7 (permalink)  
Old 01-09-12, 12:19
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
Sure, no problem. But you could have tested that query first. Doing so, you'd see that
a) it is invalid (from a space in a table name to an ambiguously defined column)
b) it produces wrong results
Reply With Quote
  #8 (permalink)  
Old 01-10-12, 04:09
pstnc pstnc is offline
Registered User
 
Join Date: Jan 2012
Posts: 12
Quote:
Originally Posted by vishnusivanpillai View Post
Hi,
Anyone can help me with this I have 2 table,
say

Table A
------------
id
---
1
2
3

Table B.
---------------
id name
------- ----------
1 saj
3 vnu
4 dad
1 saj
I want result as follow

id name
-------------------
1 saj
2
3 vnu

ie, result should contain all elements of A, corresponding field of B if it exist, Eliminate duplicate rows
I don't understand nothing., post your query and see where is the error.
Reply With Quote
  #9 (permalink)  
Old 01-10-12, 08:53
beilstwh beilstwh is offline
Lead Application Develope
 
Join Date: Jun 2004
Location: Liverpool, NY USA
Posts: 2,222
read up on outer join and distinct. we will give clues but won't solve homework.
__________________
Bill
You do not need a parachute to skydive. You only need a parachute to skydive twice.
Reply With Quote
  #10 (permalink)  
Old 01-13-12, 12:02
jignesh_foryou jignesh_foryou is offline
Registered User
 
Join Date: Jul 2011
Location: Nasik, Maharastra
Posts: 5
You can get exactly same result by following both query, but read up on OUTER JOIN as all respected suggested.


SQL> select a.id,nam from a,b
2 where a.id=b.id(+)
3 order by a.id;

ID NAM
---------- -----
1 abc
2
3 aabc


SQL> select id,b1.nam from a a1 left outer join b b1 using (id) order by id;

ID NAM
---------- -----
1 abc
2
3 aabc

keep it up.
Reply With Quote
Reply

Tags
duplicate, left join, table join

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On