I want to select distinct count(id) as activeusers from a table where useractive=1, but at the same time I want to select all the users example distinct Count(id) as totalusers regardless of activestate. How to achieve this in a SQL query?
-
Hello, you want to query twice the same table, so you need to use a joined query. Select count(table1.id) as totalusers, count(table2.id) from mytable table1, mytable table2 where table2.useractive = 1 There are other prettier solutionsAmandine FAURILLOU– Amandine FAURILLOU2024-06-18 07:26:00 +00:00Commented Jun 18, 2024 at 7:26
-
2Please tag the RDBMS you useJonas Metzler– Jonas Metzler2024-06-18 07:30:54 +00:00Commented Jun 18, 2024 at 7:30
Add a comment
|