Table 1
"id" "name" "description" "path" "country" "status"
"1" "Title 1" "Description 1" "US > Consumer > Home Applicances" "US" "0"
"2" "Title 2" "Description 2" "US > Business > Legal Charges" "UK" "0"
I'm trying to do two counts with different wheres from the same table.
I came across other questions here, but none like the way I'm doing it.
I'm currently doing it with two sqls and a lot more code:
select count(id) from table where id = 1 and select count(id) from table where id = 2
If both were there, I'll go on with the rest of my script. How can I do something like this in MySql?
You can use subselects.
SELECT * FROM
(SELECT COUNT(id) AS count_one FROM table WHERE id = 1) a,
(SELECT COUNT(id) AS count_two FROM table WHERE id = 2) b
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