Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting MySQL query with several table joins or multiple select
    primarykey
    data
    text
    <p>I am trying to write a MySQL query that gives me results of Organisation Name, its Post Code, any Events that belong to the Organisation and the Post Code of that Event. I've tried all sorts of of join, join and select combinations to no avail. Is this something that is possible ? (I could have a separate table for Org Address and Event Address but it seems like it should be possible to use just one table)</p> <p>My table structures:</p> <pre><code>mysql&gt; DESCRIBE cc_organisations; +-------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | user_id | int(10) unsigned | NO | MUL | NULL | | | type | enum('C','O') | YES | | NULL | | | name | varchar(150) | NO | MUL | NULL | | | description | text | YES | | NULL | | +-------------+------------------+------+-----+---------+----------------+ 5 rows in set (0.00 sec) mysql&gt; DESCRIBE cc_events; +-------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | org_id | int(10) unsigned | NO | MUL | NULL | | | name | varchar(150) | NO | MUL | NULL | | | start_date | int(11) | NO | MUL | NULL | | | end_date | int(11) | YES | MUL | NULL | | | start_time | int(11) | NO | | NULL | | | end_time | int(11) | NO | | NULL | | | description | text | YES | | NULL | | +-------------+------------------+------+-----+---------+----------------+ 8 rows in set (0.00 sec) mysql&gt; DESCRIBE cc_addresses; +--------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | org_id | int(10) unsigned | YES | MUL | NULL | | | event_id | int(10) unsigned | YES | MUL | NULL | | | post_code | varchar(7) | NO | MUL | NULL | | | address_1 | varchar(100) | NO | | NULL | | | address_2 | varchar(100) | YES | | NULL | | | town | varchar(50) | NO | | NULL | | | county | varchar(50) | NO | | NULL | | | email | varchar(150) | NO | | NULL | | | phone | int(11) | YES | | NULL | | | mobile | int(11) | YES | | NULL | | | website_uri | varchar(150) | YES | | NULL | | | facebook_uri | varchar(250) | YES | | NULL | | | twitter_uri | varchar(250) | YES | | NULL | | +--------------+------------------+------+-----+---------+----------------+ 14 rows in set (0.00 sec) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload