SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 MYSQL Complex Join
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mdi45
Starting Member

2 Posts

Posted - 04/21/2013 :  21:25:50  Show Profile  Reply with Quote
Hello, I'm new to joins. Can anyone tell me what SELECT statement I need to get the output shown?

Note, this needs to be done with a MYSQL database.


create table a(e int,f int);
create table b(e int,g int);
create table c(e int,h int);

insert into a values(1,5);
insert into a values(2,6);
insert into b values(1,7);
insert into b values(3,2);
insert into c values(1,8);
insert into c values(4,2);

select ...         <<---- what kind of select statment goes here?


+------+------+------+------+
| e    | f    | g    | h    |
+------+------+------+------+
|    1 |    5 |    7 |    8 |
+------+------+------+------+
|    2 |    6 |      |      |
+------+------+------+------+
|    3 |      |    2 |      |
+------+------+------+------+
|    4 |      |      |    2 |
+------+------+------+------+

Edited by - mdi45 on 04/21/2013 21:28:34

MuMu88
Aged Yak Warrior

547 Posts

Posted - 04/21/2013 :  23:14:31  Show Profile  Reply with Quote
SQLTeam is a MS SQL Server website.
Post MySQL questions at http://dbforums.com/ or
http://forums.mysql.com/
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2202 Posts

Posted - 04/22/2013 :  00:36:17  Show Profile  Reply with Quote
I think there is no direct FULL OUTER JOIN in MySQL..
--MySQL Query
SELECT a.e, a.f, b.g, c.h
FROM a
LEFT JOIN b ON a.e= b.e
LEFT JOIN c on b.e=c.e
UNION ALL
SELECT a.e, a.f, b.g, c.h
FROM a
RIGHT JOIN b ON a.e= b.e
RIGHT JOIN c on b.e=c.e


--
Chandu
Go to Top of Page

mdi45
Starting Member

2 Posts

Posted - 04/22/2013 :  00:48:36  Show Profile  Reply with Quote
ok, so simulate a full outer join?

Edited by - mdi45 on 04/22/2013 00:49:44
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2202 Posts

Posted - 04/22/2013 :  00:53:15  Show Profile  Reply with Quote
quote:
Originally posted by mdi45

ok, so simulate a full outer join?


that's why I provided solution using LEFT and RIGHT OUTER JOINs....


--
Chandu
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000