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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 query with a sub-query

Author  Topic 

SQLS33ker
Starting Member

16 Posts

Posted - 2014-05-05 : 18:50:53
Hi there,

I have this query:


select subquery.inp_alloc_stat2 from
(select P.inp_alloc_stat inp_alloc_stat2 from test.mpi_involved_prof p
group by p.inp_alloc_stat) subquery
LEFT OUTER JOIN (select g.gen_prefix gen_prefix2, g.gen_code gen_code2, g.gen_desc gen_desc2 from test.lup_generic) g
on subquery.inp_alloc_stat2 = g.gen_code2


I used a left outer join because I want to preserve all records from table p PLUS matching records from g. I just want to check to see if the syntax is correct.

Thanks

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-05-06 : 11:58:05
Syntactically, it appears correct. However, there is no real need to select from test.lup_generic and make it a derived table, you can simply join to the table.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-05-09 : 05:47:16
you're not selecting any fields from g in the select list then why do you need LEFT JOIN part?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -