Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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?
SELECT a.Cnt, ... FROM (SELECT COUNT(1) as Cnt FROM ... WHERE ...) as a WHERE 1 = a.Cnt...
Your WHERE Clause does not make much sense as it is applied like a filter here. (ie; similar to WHERE myCount = 1)
WHERE Clause
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
Add a comment
Yes :
select * from (select count(0) as cnt from .......) as a where 1 = case when a.cnt = 1 Then 1 ELSE ............
Required, but never shown
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.
Explore related questions
See similar questions with these tags.
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.