Solved

Need sql query to retrieve result

Posted on 2011-03-24
6
470 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

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)

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now