| |
|
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.
|
 |

01-09-12, 00:58
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 1
|
|
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.
|

01-09-12, 01:14
|
|
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.
|
|

01-09-12, 02:31
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 5
|
|
|
|
select id,name from table A, table B where table A.id=table b.id;
|
|

01-09-12, 03:48
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,540
|
|
Quote:
Originally Posted by gocool
select id,name from table A, table B where table A.id=table b.id;
|
nice try, but sorry, no cigar
|
|

01-09-12, 03:54
|
|
Registered User
|
|
Join Date: Nov 2003
Posts: 2,408
|
|
Quote:
Originally Posted by gocool
select id,name from table A, table B where table A.id=table b.id;
|
Read up on outer joins
|
|

01-09-12, 04:13
|
|
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...
|
|

01-09-12, 12:19
|
|
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
|
|

01-10-12, 04:09
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 12
|
|
Quote:
Originally Posted by vishnusivanpillai
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.
|
|

01-10-12, 08:53
|
|
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.
|
|

01-13-12, 12:02
|
|
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. 
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|