Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Selecting values from 2 tables, display 1 result

Author  Topic 

iNko
Starting Member

19 Posts

Posted - 2013-01-22 : 10:17:16
Hey, i need help with a code that would take a values from 2 columns, and show only 1 result if theres more than 1..

Table1
ID-Name
1-Name1
2-Name2

Table2
ID-Name
1-Name1
5-Name5

I want something like this:
SELECT name FROM Table1 OR Table2 WHERE id='1'

Also when it returns (Name1, Name1) result, i would want it to be just (Name1).

Can someone help me with this? ty.

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-01-22 : 10:57:33
[code]SELECT
COALESCE(a.id,b.id) AS id,
COALESCE(a.Name, b.Name) AS NAME
FROM
Table1 a
FULL JOIN Table2 b ON
a.id = b.id;[/code]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-23 : 01:00:35
[code]
SELECT Name FROM Table1
UNION
SELECT Name FROM Table2
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -