| | |
Joins
Please support our MS SQL advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2005
Posts: 483
Reputation:
Solved Threads: 19
ok, i am assuming that you want a name for all id's. if a has an entry use that, otherwise use the name from b. also assuming that B has an entry for every id. if those assumptions are correct, then this should work
MS SQL Syntax (Toggle Plain Text)
SELECT b.id, isnull(a.name,b.name) AS [Name] FROM b LEFT JOIN a ON b.id = a.id
Or maybe:
MS SQL Syntax (Toggle Plain Text)
SELECT b.id, isnull(a.name,b.name) AS [Name] FROM b LEFT JOIN a ON b.[Name] = LEFT(a.[Name],1)
Hmm not really, it replaces the assumption that a.id is a foreign key to b.id.
The OP does not specify. If there is a relation between the id's (which there should be in my opinion, and if the data provided represents all possibilities, then this is indeed the case) your solution is the more efficient.
However if the id's are not related then that only leaves the initial letters, in which case my alternate solution will do.
The OP does not specify. If there is a relation between the id's (which there should be in my opinion, and if the data provided represents all possibilities, then this is indeed the case) your solution is the more efficient.
However if the id's are not related then that only leaves the initial letters, in which case my alternate solution will do.
•
•
Join Date: Sep 2007
Posts: 14
Reputation:
Solved Threads: 1
•
•
•
•
ok, i am assuming that you want a name for all id's. if a has an entry use that, otherwise use the name from b. also assuming that B has an entry for every id. if those assumptions are correct, then this should work
MS SQL Syntax (Toggle Plain Text)
SELECT b.id, isnull(a.name,b.name) AS [Name] FROM b LEFT JOIN a ON b.id = a.id
Thanks to reply my query. It worked.
Last edited by bhakti.thakkar; Jan 28th, 2008 at 12:36 am.
![]() |
Similar Threads
- Mysql Joins Assistance (MySQL)
- Wordpress, Joins and Indexes (MySQL)
- Sql Joins (MySQL)
- MS SQL Joins - newb assistance (MS SQL)
- Joins (MySQL)
- Problem with Rewriting Subqueries as Joins (Database Design)
- Problem with Rewriting Subqueries as Joins (MS SQL)
Other Threads in the MS SQL Forum
- Previous Thread: StoredProcedure @variable = table.field not working
- Next Thread: Wierd maintenance plan problem
| Thread Tools | Search this Thread |
autogrowth connectingtodatabaseinuse count cursor data database datepart dbsize deadlock delete_trigger highperformancecomputing hpc hpcserver2008 ibm iis loop maximum microsoft ms mssql multithreading news number permission query reporting result server services sets source sql sqlserver sqlserver2005 supercomputing uniqueid update view






