Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 MYSQL Complex Join

Author  Topic 

mdi45
Starting Member

2 Posts

Posted - 2013-04-21 : 21:25:50
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 |
+------+------+------+------+

MuMu88
Aged Yak Warrior

549 Posts

Posted - 2013-04-21 : 23:14:31
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-22 : 00:36:17
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 - 2013-04-22 : 00:48:36
ok, so simulate a full outer join?
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-22 : 00:53:15
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
   

- Advertisement -