1

I have this SQL Query,

select * from (select * from .......) as a
where 1 = case when CountOfInnerSelect = 1 Then 1 ELSE ............

Is it possible I can get Count of inner select inside the outer SELECT?

1
  • 1
    You can select the count from subquery then use it. SELECT a.Cnt, ... FROM (SELECT COUNT(1) as Cnt FROM ... WHERE ...) as a WHERE 1 = a.Cnt... You can do it without selecting it in your result. Commented Nov 26, 2012 at 9:06

2 Answers 2

1

Your WHERE Clause does not make much sense as it is applied like a filter here. (ie; similar to WHERE myCount = 1)

SELECT * FROM
(SELECT c1,c2,c3,..,Cn,COUNT(*) AS myCount
 FROM YourTable
 GROUP BY c1,c2,c3,..,Cn
) A
WHERE 1 = CASE myCount WHEN 1 THEN 1 ELSE... END
Sign up to request clarification or add additional context in comments.

Comments

1

Yes :

select * from (select count(0) as cnt from .......) as a
where 1 = case when a.cnt = 1 Then 1 ELSE ............

1 Comment

I need to select my coulmns in the inner select as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.