January 21, 2009 at 1:59 am
i have 3 tables like this
t1 --->table1
t1Id t1Name
1 jj
2 qq
t2----->table2
t2Id t2Name
1 rr
2 uu
t3---table 3
t3Id tableName
1 t1
2 t1
1 t2
2 t2
i need the foolwing result
name
jj
rr
uu
January 21, 2009 at 2:05 am
What are the relations among these tables? Describe more about expected result.
Regards,
Nitin
January 21, 2009 at 2:26 am
One way of getting your results is by running the fallowing query:
select name from table1
Union all
select name from table2
I have to admit that I there is a good chance that you want something else. In that case pleas use the URL in my signature to learn how to post the questions in a way that will get you faster and better answers.
Adi
--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
January 21, 2009 at 6:21 am
How does table 3 relate to the others?
Also, didn't this get posted before in the same form?
----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software
January 21, 2009 at 6:25 am
It looks like simple UNION ALL operation. But still it is not clear, what exact requirement is?
Regards,
Nitin
January 21, 2009 at 7:17 am
..Since you haven't provided enough information, I could only find the probables and this is what I think is the most probable...
SELECT t12.t12Name
FROM table3 t3
INNER JOIN
(
SELECT t1Id AS t12Id, t1Name AS t12Name, 't1' AS RecordType
FROM table1
UNION ALL
SELECT t2Id, t2Name, 't2' AS RecordType
FROM table2
) t12 ON t3.t3Id = t12.t12Id AND t3.tableName = t12.RecordType
--Ramesh
January 21, 2009 at 7:22 am
The same question was posted here:
http://qa.sqlservercentral.com/Forums/Topic639228-145-1.aspx
You responded to that post also.
January 21, 2009 at 7:41 am
Kent Waldrop (1/21/2009)
The same question was posted here:http://qa.sqlservercentral.com/Forums/Topic639228-145-1.aspx
You responded to that post also.
I thought I remembered seeing that before.
----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply