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
 A SELECT statement with just sub-selects?

Author  Topic 

Maverick_
Posting Yak Master

107 Posts

Posted - 2012-11-06 : 05:49:33
Hi all,

Is it possible to write a SELECT statement with just sub-selects? I don't need a FROM for a query I am writing.

E.g.

SELECT

(SELECT count(job.job_number)
FROM
job,
job_status_log
WHERE
job.job_number = job_status_log.job_number AND
job.job_log_number = job_status_log.job_log_number AND
job.job_status_flag = 'C' AND
job_status_log.status_code IN ('J020', 'J020', 'J040')) as Orders_Issued_Awaiting_Completion

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2012-11-06 : 06:26:32
So, why is this a nested select? Just select your count. Also, you should really use the LEFT JOIN, INNER JOIN syntax instead of joining in the where clause.








How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-11-06 : 06:26:35
It is not possible for sub-query..

You have to write FROM clause to get sub-query...

For your query, no need of outer SELECT at all know.......?

--
Chandu
Go to Top of Page
   

- Advertisement -