I have two SQL queries for counting the rows from the table tContentNode
, depending on the type 2 or 3.
Query 1:
SELECT count(*) _countA FROM TCONTENTNODE WHERE type = '2'
AND parentid ='02b3abc2-4983-485a-ab09-1a8cb328b9b5';
Query 2:
SELECT count(*) _countB FROM TCONTENTNODE WHERE type = '3'
AND parentid ='02b3abc2-4983-485a-ab09-1a8cb328b9b5';
Now I want to get the values of _countA
and _countB
using only one query. How can I get the counts using one query. Is there any way to do that. I am using SQLite Database.
EDIT:
I want values of _countA
and _countB
separately, not both together(Not using IN
).
I solved the problem using the following query:-
SELECT
COUNT(case TCONTENTNODE.type when '2' then 1 end) as _countA,
COUNT(case TCONTENTNODE.type when '3' then 1 end) as _countB
FROM TCONTENTNODE
WHERE TCONTENTNODE.parentid ="02b3abc2-4983-485a-ab09-1a8cb328b9b5";
Dont have SQLite to confirm but
select count(*), type FROM TCONTENTNODE WHERE (type = '2' or type = '3' )
AND parentid ='02b3abc2-4983-485a-ab09-1a8cb328b9b5' group by type
Just to clarify this will return
count type
23 2
23888 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With