HQL left join of un-related entities

Currently, the theta-style on joining the unrelated classes in the where clause using HQL only supports inner join. The request for supporting the outer join for such situation is currently the 3-rd most voted enhancement but I don’t think this feature will be implemented in the near feature as it requires the re-implementation of the … 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.

MySQL select rows where left join is null

You could use the following query: SELECT table1.id FROM table1 LEFT JOIN table2 ON table1.id IN (table2.user_one, table2.user_two) WHERE table2.user_one IS NULL; Although, depending on your indexes on table2 you may find that two joins performs better: SELECT table1.id FROM table1 LEFT JOIN table2 AS t1 ON table1.id = t1.user_one LEFT JOIN table2 AS t2 … Read more

Select first record in a One-to-Many relation using left join

After playing around a bit, this turns out to be trickier than I’d expected! Assuming that table_b has some single column that is unique (say, a single-field primary key), it looks like you can do this: SELECT table_a.code, table_a.emp_no, table_b.city, table_b.county FROM table_a LEFT JOIN table_b ON table_b.code = table_a.code AND table_b.field_that_is_unique = ( SELECT … Read more

Entity Framework include with left join is this possible?

Yes, it is possible. Firstly, .Include does a LEFT OUTER JOIN, using the navigational property you pass through. This is how you would explicitly do a LEFT JOIN between Student and StudentDescription: var query = from s in ctx.Students from sd in s.StudentDescriptions.DefaultIfEmpty() select new { StudentName = s.Name, StudentDescription = sd.Description }; As you … Read more

Insert using LEFT JOIN and INNER JOIN

You have to be specific about the columns you are selecting. If your user table had four columns id, name, username, opted_in you must select exactly those four columns from the query. The syntax looks like: INSERT INTO user (id, name, username, opted_in) SELECT id, name, username, opted_in FROM user LEFT JOIN user_permission AS userPerm … Read more

MySQL joins and COUNT(*) from another table

MySQL use HAVING statement for this tasks. Your query would look like this: SELECT g.group_id, COUNT(m.member_id) AS members FROM groups AS g LEFT JOIN group_members AS m USING(group_id) GROUP BY g.group_id HAVING members > 4 example when references have different names SELECT g.id, COUNT(m.member_id) AS members FROM groups AS g LEFT JOIN group_members AS m … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)