SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Nov 27, 2009, 08:29 #1
- Join Date
- Nov 2009
- Location
- Bangalore, India
- Posts
- 52
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Actual value instead of Null in result of MySQL Left join
I have two tables ; table1 and table 2,
table1 has fields - f1, f2 and f3
table2 has fields - f1, f2 and f4
Code:table1 table2 f1 f2 f3 f1 f2 f4 2 3 4 2 3 6 5 8 7 5 8 7 11 13 15 11 13 17
Code:select table1.*,table.f4 from table1 left join tester on (table1.f1 = table2.f1 and table1.f2 = table2.f2 and table1.f3 = table2.f4);
Output I am getting is
Code:f1 f2 f3 f4 2 3 4 null 5 8 7 7 11 13 15 null
But the Output I want is
Code:f1 f2 f3 f4 2 3 4 6 5 8 7 7 11 13 15 17
Thank You
Known is a Drop, Unknown is an Ocean
-
Nov 27, 2009, 08:46 #2
- Join Date
- May 2007
- Location
- Poole, UK
- Posts
- 5,077
- Mentioned
- 103 Post(s)
- Tagged
- 0 Thread(s)
Code SQL:SELECT table1.* , table2.f4 FROM table1 LEFT JOIN table2 ON table1.f1 = table2.f1
Community Team Advisor
Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator
-
Nov 29, 2009, 19:25 #3
- Join Date
- Nov 2009
- Location
- Bangalore, India
- Posts
- 52
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Nov 29, 2009, 20:33 #4
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
the query he provided gives exactly the result set you said you wanted
here, you may borrow this code and test it for yourself --Code:CREATE TABLE table1 ( f1 INTEGER , f2 INTEGER , f3 INTEGER ); INSERT INTO table1 VALUES ( 2 , 3 , 4 ) ,( 5 , 8 , 7 ) ,( 11 , 13 , 15 ) ; CREATE TABLE table2 ( f1 INTEGER , f2 INTEGER , f4 INTEGER ); INSERT INTO table2 VALUES ( 2 , 3 , 6 ) ,( 5 , 8 , 7 ) ,( 11 , 13 , 17 ) ; SELECT table1.* , table2.f4 FROM table1 LEFT OUTER JOIN table2 ON table2.f1 = table1.f1 ;
-
Nov 29, 2009, 20:33 #5
- Join Date
- Nov 2003
- Location
- Huntsville AL
- Posts
- 706
- Mentioned
- 4 Post(s)
- Tagged
- 1 Thread(s)
Bookmarks