February 6th, 2013, 10:59 AM
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
Moved to the MySQL forum.
February 6th, 2013, 11:23 AM
SELECT companies.name AS company_name
ON companies.id = members.company
February 6th, 2013, 01:13 PM
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?
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
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
Ah. Thanks for the clarity.