Questions tagged [left-join]

A left join is an outer join which generates a result that contains all the records of the "left" table even when there are no matching records in other tables taking part in the join.

SQL LEFT JOIN ON returns the rows of INNER JOIN ON plus unmatched left table rows extended by NULLs. A consequence is that it returns all the rows from the left table at least once even if there are no matches in the left table. So if the ON clause matches 0 (zero) records in the left table then the join will still return that row extended by a NULL in each column from the right table.


Specific join tags

You can specify your question by adding extra tags:


Questions

8172 questions
2
votes
1 answer

SQL select with inner join, sub select and limit

I've been working with this SQL problem for about 2 days now and suspect I'm very close to resolving the issue but just can't seem to find a solution that completely works. What I'm attempting to do is a selective join on two tables called…
Rick Sarvas
  • 769
  • 10
  • 20
2
votes
3 answers

right join versus left join

In this case, a left join is the same as a right join? mysql> mysql> mysql> use usenet;show tables;describe ARTICLE;describe NEWSGROUP; Database changed +------------------+ | Tables_in_usenet | +------------------+ | ARTICLE | |…
Thufir
  • 8,216
  • 28
  • 125
  • 273
2
votes
1 answer

Left Join After Where Clause

I'm having trouble with this query that fetches sorts forum topics on the number of replies in a different table. I tried this with Left join before the where but some data was left out in my while loop. SELECT forum_topics.*,…
keji
  • 5,947
  • 3
  • 31
  • 47
2
votes
3 answers

In MySQL, how to use a subquery to a left join statement?

I tried to count how many new tuples are in a subset of t2 as compared to t1 by SELECT COUNT(t2.id) FROM ( (SELECT id, col1 FROM t2 WHERE col2=0 AND col3=0) AS t LEFT OUTER JOIN t1 ON t.id=t1.id ) WHERE t1.id IS NULL; The subset…
qazwsx
  • 25,536
  • 30
  • 72
  • 106
2
votes
3 answers

sql: why does query repeat values when using 'GROUP CONCAT' + 'GROUP BY'?

The Query: SELECT MemberId, a.MemberName, GROUP_CONCAT(FruitName) FROM a LEFT JOIN b ON a.MemberName = b.MemberName GROUP BY a.MemberName Table a MemberID MemberName -------------- ---------- 1 Al …
Adam
  • 405
  • 1
  • 5
  • 22
2
votes
2 answers

MYSQL Query Cross Database Join return NULL

select t1.CardID,t2.Description,t5.BioData from db2.tblemployeeinfob t1 left join (db2.tbldepartments t2,db1.tblbiometrics t5) on (t1.Department = t2.DepartmentID and t1.CardID=t5.CardID ) Return Result is 1420 | (NULL) | (NULL) Expected Result…
Wasim A.
  • 9,660
  • 22
  • 90
  • 120
2
votes
2 answers

Left Outer Join works in LINQPad (connected using EF 4.3) but fails in application

I have an application that successfully utilizes LINQ to perform LEFT OUTER JOINs several instances; however, in one case it fails to work as expected. Testing in LINQPad (using LINQ-to_SQL) produced the correct result; however, to be sure I…
user646306
  • 503
  • 1
  • 5
  • 16
2
votes
2 answers

Best way to do multiple left outer excluding joins

I have one table that I need to bump against multiple tables with left outer joins excluding the right(s). Is there a best practice for this? Union all the other tables first? Something else? Here's the first thought that comes to my mind to handle…
dscl
  • 1,616
  • 7
  • 28
  • 48
2
votes
2 answers

joining tables with not exists query

Possible Duplicate: Mysql: Perform of NOT EXISTS. Is it possible to improve permofance? Is there a better/optimal way to do it. Should I use exists instead of join? Or two separate queries? And what about temporary tables, as I was reading about…
timeout
  • 35
  • 5
2
votes
1 answer

MySQL Join + "WHERE something=MAX(something)"

I have a couple of tables that need to be be joined. The tables are: players first_name last_name gender location_id (additional irrelevant columns) and score_entries score datetime player_id (additional irrelevant columns) I need to join them…
user1418227
  • 201
  • 1
  • 4
  • 12
2
votes
3 answers

TSQL Left Join with multiple right hand rows

When you perform a left join in TSQL (MSSQL SERVER) is there any guarantee which row will return with your query if there are multiple rows on the right? I'm trying to use this to exploit an ordering on the right table. so Select ColA, ColB, ColC…
Spence
  • 28,526
  • 15
  • 68
  • 103
2
votes
4 answers

Difference between Condition in Where and Condition in Join

Can anyone please explain to me why the following two queries yield different results? SELECT o.* FROM Customer c LEFT JOIN [Order] o ON o.CustomerID = c.CustomerID AND o.OrderType = 'Cash' WHERE c.Country = 'USA' SELECT …
staterium
  • 1,980
  • 2
  • 20
  • 32
2
votes
2 answers

MySQL: How to LEFT JOIN WHERE IS NULL (user1 blocks user2 OR upside down)?

I have a table user and in addition INNER JOIN it with table cities and a few others already. Now I also have the following table: blocked_user -------------------------------------------------------- id | user1_id | user2_id | timestamp How can I…
Chris
  • 3,756
  • 7
  • 35
  • 54
2
votes
1 answer

mysql join where the difference between values is minimal?

In principle I have 2 tables T1 and T2, each containing a date-field, lets call it date: T1: date | somekey | data ... T2: date | somekey | data ... I want to (left)join T1 and T2, such that the result has all rows from T1. Now for each row from…
IARI
  • 1,217
  • 1
  • 18
  • 35
2
votes
5 answers

How to get all rows from left table in a join statement?

I have two tables. One is Employee_Mstr and other is EmployeeLeaveRequest_mstr. My data:
Tripati Subudhi
  • 1,651
  • 10
  • 22
  • 26
1 2 3
99
100