View previous topic :: View next topic
|
Author |
Message |
sijayapal
New User
Joined: 23 Dec 2008 Posts: 69 Location: India
|
|
|
|
Hi,
I have two tables table1 and table2. Both tables have a field named "column". I need to get all the values of the field column in a single select.
Select Column
From Table1, Table2
Where condition.
column must display datas from both the tables. Is there any possible way to Achieve this?
|
|
Back to top |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
|
|
Sija,
You can use UNION. |
|
Back to top |
|
|
sijayapal
New User
Joined: 23 Dec 2008 Posts: 69 Location: India
|
|
|
|
Srihari,
Tats right i can use union. Is there any other way???
Union consumes lot of time and performance degrades. |
|
Back to top |
|
|
dejunzhu
Active User
Joined: 08 May 2008 Posts: 390 Location: China
|
|
|
|
You can use INTERSECT in your SQL statement. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
Back to top |
|
|
apandey
New User
Joined: 31 Aug 2009 Posts: 73 Location: Mumbai
|
|
|
|
Again,Here also i will suggest to use OUTER JOIN. Joins are explicitly meant to fetch the data from one or more tables. Unions bascially joins
the results of 2 tables by removing duplicates. |
|
Back to top |
|
|
Ketan Varhade
Active User
Joined: 29 Jun 2009 Posts: 197 Location: Mumbai
|
|
|
|
Hi,
Quote: |
Again,Here also i will suggest |
Where else???? |
|
Back to top |
|
|
ajeshrn
New User
Joined: 25 Mar 2009 Posts: 78 Location: India
|
|
|
|
Hi sijayapal,
We can do it...Please check whether the below query returns results as you expect.
SELECT T1.COLUMN || T2.COLUMN AS COLUMN
FROM TABLE1 T1
LEFT JOIN TABLE2 T2
ON <CONDITION> |
|
Back to top |
|
|
lkhiger
New User
Joined: 28 Oct 2005 Posts: 89
|
|
|
|
ajeshrn wrote: |
Hi sijayapal,
We can do it...Please check whether the below query returns results as you expect.
SELECT T1.COLUMN || T2.COLUMN AS COLUMN
FROM TABLE1 T1
LEFT JOIN TABLE2 T2
ON <CONDITION> |
May I ask you: Why you use "LEFT JOIN" not "FULL JOIN" ?
Something like this:
Code: |
SELECT coalesce(T1.COLUMN, '') || coalesce(T2.COLUMN, '') AS COLUMN
FROM TABLE1 T1
Full JOIN TABLE2 T2
ON <CONDITION> |
Thanks. |
|
Back to top |
|
|
mallik4u
New User
Joined: 17 Sep 2008 Posts: 75 Location: bangalore
|
|
|
|
Hi Sijayapal,
Using JOINs we will be able to combine two combine two tables (results).
Ex:
T1. COLUMN
ABC
BBC
CBC
T2.COLUMN
ZBC
YBC
XBC
If we use JOIN (either FULL/LEFT/RIGHT) then two columns will be comined (concatinated) into one column like the following.
COLUMN
ABC ZBC
BBC YBC
CBC XBC.
But if you want the second table column to join after the first table column then we have use UNION/UNION ALL.
COLUMN
ABC
BBC
CBC
ZBC
YBC
XBC.
Reading your question/doubt, i feel that you have to use UNION/UNIONALL.
Please let me know if my understanding is wrong. |
|
Back to top |
|
|
ajeshrn
New User
Joined: 25 Mar 2009 Posts: 78 Location: India
|
|
|
|
Hi lkhiger,
Using a LEFT JOIN / FULL JOIN depends on the requirement.I have given a sample query which will fetch the records of TABLE1 and TABLE2 in the same row. |
|
Back to top |
|
|
|