[thelist] [SQL] selecting info from two tables (?)

Paul Bennett paul at teltest.com
Tue Aug 12 22:07:57 CDT 2003


I have three MySQL tables:

I am querying the "events" table, which gives me (among other things) a 
userId. I want to then get the organisationID of this user (if any) from 
the "users" table and get the organisation name corresponding to this id 
from the "organisations" table in ONE query. Am I dreaing, or is this 
possible

<cough>rudy?</cough>

table "events":

id int(11) NOT NULL auto_increment PRIMARY KEY,
userId int(11) NOT NULL default '0',
start varchar(20) NOT NULL default '',
stop varchar(20) NOT NULL default '',
zone varchar(4) NOT NULL default '',
notified enum('y','n') NOT NULL default 'n',
notified_time varchar(14) NOT NULL default '',

table "users":

userId int(11) NOT NULL default '0',
orgId int(11) NOT NULL default '0',
(plus a whole heap of extraneous fields not important to this question)

table "organisations"

id int(11) NOT NULL auto_increment,
  org_name tinytext NOT NULL,
(plus a whole heap of extraneous fields again not important to this question)


Many thanks, SQL guru's

-- 
 ------------------------------
	Paul Bennett						
	Internet Developer				
	Teltest Electronic Design		
 ------------------------------			
Email: paul at teltest.com				
Phone: 64 4 237 4557					
Web: http://www.teltest.com		
Wap: http://wap.teltest.com			




More information about the thelist mailing list