SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 query with a sub-query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

SQLS33ker
Starting Member

USA
13 Posts

Posted - 05/05/2014 :  18:50:53  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 05/06/2014 :  11:58:05  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 05/09/2014 :  05:47:16  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.22 seconds. Powered By: Snitz Forums 2000