Search
 
SCRIPT & CODE EXAMPLE
 

SQL

mysql count with two joins

select
  t.Topic,
  t.Title,
  s.StarCount,
  m.UserCount,
  m.MessageCount
from
  Topics t
  left join (
    select 
      Topic, 
      count(distinct User) as UserCount,
      count(*) as MessageCount
    from Messages
    group by Topic
  ) m ON m.Topic = t.Topic
  left join (
    select
      Topic, 
      count(*) as StarCount
    from Stars_Given 
    group by Topic
  ) s ON s.Topic = t.Topic
Comment

PREVIOUS NEXT
Code Example
Sql :: sum over partition by postgresql 
Sql :: power bi dax add related shows column but not working 
Sql :: SQL create table full of dates 
Sql :: hive batch drop table 
Sql :: ACCEPT nome PROMPT on oracle 
Sql :: firebase sql 
Sql :: ring MySQL Create Database 
Sql :: how to fetch highest score in minimum time using mysql 
Sql :: select even number id data from table 
Sql :: Grant read-only privilleges to the user 
Sql :: in sql developer where equal queres 
Sql :: 10 random questions use python and SQL 
Sql :: mysql order by where condition sub query 
Sql :: https://stackoverflow.com/questions/52997573/how-to-connect-to-sql-database-with-react 
Sql :: mysql find the row ites of the hoghest value at on column 
Sql :: connect to remote mysql server 
Sql :: how to insert multiple values in a single column in sql 
Sql :: sql multi row insert 
Sql :: run sql command line download 
Sql :: raiserror sql 
Sql :: mysql insert into select transaction c# 
Csharp :: c# mark as deprecated 
Csharp :: unity quit in edtor 
Csharp :: c# getasynckeystate mouse 
Csharp :: unity get all by tag 
Csharp :: unity exit application 
Csharp :: unix time c# 
Csharp :: asp.net data annotations Datetime 
Csharp :: c# loop datatable rows 
Csharp :: c# convert Unix time in seconds to datetime 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =