how can i combine these two queries in mysql?
select count(*) as entry_count from tbl_entries where user_id = x
and
select username, avatar from tbl_users where user_id = x
I want one result that combines the result of this 2 queries. Please help me guys!
Thanks!
The use of COUNT() function in conjunction with GROUP BY is useful for characterizing our data under various groupings. A combination of same values (on a column) will be treated as an individual group.
SQL SELECT statement can be used along with COUNT(*) function to count and display the data values. The COUNT(*) function represents the count of all rows present in the table (including the NULL and NON-NULL values).
COUNT(*) The COUNT(*) function returns the number of rows in a dataset using the SELECT statement. The function counts rows with NULL, duplicate, and non-NULL values. You can also use the WHERE clause to specify a condition.
The simple answer is no – there is no difference at all. The COUNT(*) function counts the total rows in the table, including the NULL values. The semantics for COUNT(1) differ slightly; we'll discuss them later. However, the results for COUNT(*) and COUNT(1) are identical.
select username,
avatar,
(select count(*) from tbl_entries where user_id = x) as entry_count
from tbl_users
where user_id = x
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