dbTalk Databases Forums  

Extended Join

comp.databases.mysql comp.databases.mysql


Discuss Extended Join in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Daniel Arnold
 
Posts: n/a

Default Extended Join - 05-03-2011 , 05:01 PM






Hi

I am just doing my first steps in SQL (SQLite3) and have to following
problem. I have the following two tables:

Table_A

ID_A name
-------------
1 Name1
2 Name2
3 Name3

Table_B

ID_B key value
-----------------------------
1 3 Jamaica
2 1 Canal Street
2 2 New York
2 3 USA
3 1 Endell Street
3 3 England

Hence, Table_B contains the street, city and country (key 1,2 and 3) of
the persons in Table_A. Now I want to join these two tables into a
single one of the following form:

name street city country
-------------------------------------------------------
Name1 Jamaica
Name2 Canal Street New York USA
Name3 Endell Street England

Using LEFT OUTER JOIN I was able to output the names and e.g. the streets:

SELECT Table_A.name,Table_B.value FROM Table_A LEFT OUTER JOIN Table_B
ON Table_A.ID_A=Table_B.ID_B AND Table_B.key=1

But how could I simultaneously output the cities and countries in addition?

Many thanks and best regards,
Daniel

Reply With Quote
  #2  
Old   
onedbguru
 
Posts: n/a

Default Re: Extended Join - 05-03-2011 , 05:49 PM






On May 3, 6:01*pm, Daniel Arnold <flashli... (AT) students (DOT) unibe.ch> wrote:
Quote:
Hi

I am just doing my first steps in SQL (SQLite3) and have to following
problem. I have the following two tables:

Table_A

ID_A * *name
-------------
1 * * * Name1
2 * * * Name2
3 * * * Name3

Table_B

ID_B * *key * * value
-----------------------------
1 * * * 3 * * * Jamaica
2 * * * 1 * * * Canal Street
2 * * * 2 * * * New York
2 * * * 3 * * * USA
3 * * * 1 * * * Endell Street
3 * * * 3 * * * England

Hence, Table_B contains the street, city and country (key 1,2 and 3) of
the persons in Table_A. Now I want to join these two tables into a
single one of the following form:

name * * * * * *street * * * * *city * * * * * *country
-------------------------------------------------------
Name1 * * * * * * * * * * * * * * * * ** * * * Jamaica
Name2 * * * * * Canal Street * *New York * * * *USA
Name3 * * * * * Endell Street * * * * * * * * * England

Using LEFT OUTER JOIN I was able to output the names and e.g. the streets:

SELECT Table_A.name,Table_B.value FROM Table_A LEFT OUTER JOIN Table_B
ON Table_A.ID_A=Table_B.ID_B AND Table_B.key=1

But how could I simultaneously output the cities and countries in addition?

Many thanks and best regards,
Daniel

multiple left outer joins to the same table_b and use aliases for the
table name, or, rethink your logical view altogether.

Reply With Quote
  #3  
Old   
Álvaro G. Vicario
 
Posts: n/a

Default Re: Extended Join - 05-04-2011 , 07:17 AM



El 04/05/2011 0:01, Daniel Arnold escribió/wrote:
Quote:
I am just doing my first steps in SQL (SQLite3)
Er... SQLite is not MySQL. I'm not sure if you are asking here because
you couldn't find a SQLite group or you actually think they're the same
program.

:-?



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--

Reply With Quote
  #4  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: Extended Join - 05-04-2011 , 10:53 AM



Daniel Arnold wrote:

Quote:
I am just doing my first steps in SQL (SQLite3) and have to following
problem. I have the following two tables:
MySQL is an SQL variant (or dialect, if you prefer) as is SQLite,
but it is not the same as SQLite. Ask this where SQLite is on-topic.

--
PointedEars

Bitte keine Kopien per E-Mail. / Please do not Cc: me.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.