Solved

Need sql query to retrieve result

Posted on 2011-03-24
6
473 Views
Last Modified: 2012-05-11
these are my sql tables. how can i get the result here..
my table desription..


Table 1
...........
Col1 pk
Col2

Table 2
..........
Col3 pk
Col4

Table3
...........
col3 fk
col1 fk
col5

Now i want data like this

result is
.......
col2
col4

Here col2 and col4 as a single column(concatination).

Here my sql statement is failed to retrieve result..

Can anyone know sql query to get result..
0
Comment
Question by:lucky20
6 Comments
 
LVL 24

Expert Comment

by:jimyX
ID: 35210742
Select Col2 from Table1 union select Col4 from Table2 union select col5 from Table3
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35210753
To allow duplicate values use union all:
Select Col2 from Table1 union all select Col4 from Table2 union all select col5 from Table3
0
 
LVL 24

Accepted Solution

by:
jimyX earned 500 total points
ID: 35210773
Not sure i got your point there but if you just want Col2 and Col4 then:

Select Col2 from Table1 union all select Col4 from Table2
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 5

Expert Comment

by:bitref
ID: 35210779
Select t1.col2, t2.col4
From t1
	Inner Join t3 on t1.col1 = t3.col1
	Inner Join t2 on t3.col3 = t2.col3

Open in new window

0
 
LVL 32

Expert Comment

by:ewangoya
ID: 35210972

Select Col2
from Table1
union all
select Col4
from Table1
inner join Table2 on Table2.Col3=Table1.Col1
0
 
LVL 1

Author Comment

by:lucky20
ID: 35211552
thanks to every one..
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question