MYSQL Left Join COUNTS from multiple tables

select t.Topic, t.Title, count(distinct s.starID) as StarCount, count(distinct m.User) as UserCount, count(distinct m.messageID) as MessageCount from Topics t left join Messages m ON m.Topic = t.Topic left join Stars_Given s ON s.Topic = t.Topic group by t.Topic, t.Title Sql Fiddle Or, you can perform the aggregation in sub-queries, which will likely be more efficient if … Read more

Access 2007 – Left Join to a query returns #Error instead of Null

While the query should return Null based on the join type, as Allen Browne states in his article, Bug: Outer join expressions retrieved wrongly, “Instead, it behaves as if [the JET query optimizer] is evaluating the expression after it has returned the results from the lower-level query.” Consequently, you must select the calculated field using … Read more

MySQL: How do I join same table multiple times?

You need to use multiple LEFT JOINs: SELECT ticket.ticket_id, a1.attr_val AS attr_val1, a2.attr_val AS attr_val2, a3.attr_val AS attr_val3 FROM ticket LEFT JOIN attr a1 ON ticket.ticket_id=a1.ticket_id AND a1.attr_type=1 LEFT JOIN attr a2 ON ticket.ticket_id=a2.ticket_id AND a2.attr_type=2 LEFT JOIN attr a3 ON ticket.ticket_id=a3.ticket_id AND a3.attr_type=3 Here is an example: SQL Fiddle.

LINQ Inner-Join vs Left-Join

I think if you want to use extension methods you need to use the GroupJoin var query = people.GroupJoin(pets, person => person, pet => pet.Owner, (person, petCollection) => new { OwnerName = person.Name, Pet = PetCollection.Select( p => p.Name ) .DefaultIfEmpty() } ).ToList(); You may have to play around with the selection expression. I’m not … Read more

Why and when a LEFT JOIN with condition in WHERE clause is not equivalent to the same LEFT JOIN in ON? [duplicate]

The on clause is used when the join is looking for matching rows. The where clause is used to filter rows after all the joining is done. An example with Disney toons voting for president: declare @candidates table (name varchar(50)); insert @candidates values (‘Obama’), (‘Romney’); declare @votes table (voter varchar(50), voted_for varchar(50)); insert @votes values … Read more