The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Databases
> MySQL Help
|
PHP-DB - Cross reference MySQL table for SELECT?
Discuss Cross reference MySQL table for SELECT? in the MySQL Help forum on Dev Shed. Cross reference MySQL table for SELECT? MySQL Help forum discussing administration, SQL syntax, and other MySQL-related topics. MySQL is an open-source relational database management system (RDBMS).
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 6th, 2013, 10:59 AM
|
|
Contributing User
|
|
Join Date: Jun 2009
Posts: 313
  
Time spent in forums: 3 Days 15 h 8 m 35 sec
Reputation Power: 5
|
|
|
PHP-DB - Cross reference MySQL table for SELECT?
Howdy. I am going to SELECT customers from a MySQL database, and loop out a table. Everything I need is in a single table EXCEPT Company. Its id IS in this table, but I need the name. Is there a way to do something similar as:
SELECT `company`,`member`,`phone` FROM `table`
and instead of getting the 138 value in this table for `company`, have it fetch that from a different table, but use the 138 in the member table to reference it in the 2nd table? Thank for any input.
|

February 6th, 2013, 11:12 AM
|
 |
kill 9, $$;
|
|
Join Date: Sep 2001
Location: Shanghai, An tSín
|
|
|
Moved to the MySQL forum.
|

February 6th, 2013, 11:23 AM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
Code:
SELECT companies.name AS company_name
, members.member
, members.phone
FROM members
INNER
JOIN companies
ON companies.id = members.company
|

February 6th, 2013, 01:13 PM
|
|
Contributing User
|
|
Join Date: Jun 2009
Posts: 313
  
Time spent in forums: 3 Days 15 h 8 m 35 sec
Reputation Power: 5
|
|
INNER JOIN, excellent. Thank you. Trying to use that, a column has a space in it, but using tablename.column won't allow me to place backtick's around it. What shall I do?
Code:
SELECT `customers.Customer Name`,`rolodex.FLName`,`rolodex.Position`,`rolodex.Number`,`rolodex.Type`,`rolodex.E-mail`,`rolodex.Note` FROM `rolodex` INNER JOIN customers ON rolodex.CustomerID=customers.ID ORDER BY `customers.Customer Name`
Last edited by Triple_Nothing : February 6th, 2013 at 01:17 PM.
|

February 6th, 2013, 01:23 PM
|
|
Contributing User
|
|
Join Date: Jun 2009
Posts: 313
  
Time spent in forums: 3 Days 15 h 8 m 35 sec
Reputation Power: 5
|
|
Ah, backticks only go around field names, not tables. Thanks all! 
|

February 7th, 2013, 05:48 AM
|
|
|
|
No, they go round (when you need to use them) both table name and column name, but each is a separate entity, thus: `Table name`.`Column name`
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc
|

February 7th, 2013, 09:36 PM
|
|
Contributing User
|
|
Join Date: Jun 2009
Posts: 313
  
Time spent in forums: 3 Days 15 h 8 m 35 sec
Reputation Power: 5
|
|
|
Ah. Thanks for the clarity.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|