MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 6th, 2013, 10:59 AM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 313 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
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.

Reply With Quote
  #2  
Old February 6th, 2013, 11:12 AM
ishnid's Avatar
ishnid ishnid is offline
kill 9, $$;
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Sep 2001
Location: Shanghai, An tSín
Posts: 6,894 ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Months 2 Weeks 1 Day 22 h 49 m 41 sec
Reputation Power: 3885
Moved to the MySQL forum.

Reply With Quote
  #3  
Old February 6th, 2013, 11:23 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 43rd Plane (26000 - 26499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,442 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 14 h 15 m 54 sec
Reputation Power: 4141
Code:
SELECT companies.name AS company_name
     , members.member
     , members.phone 
  FROM members
INNER
  JOIN companies
    ON companies.id = members.company 
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #4  
Old February 6th, 2013, 01:13 PM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 313 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
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.

Reply With Quote
  #5  
Old February 6th, 2013, 01:23 PM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 313 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
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!

Reply With Quote
  #6  
Old February 7th, 2013, 05:48 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,111 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 7 h 43 m 38 sec
Reputation Power: 1485
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

Reply With Quote
  #7  
Old February 7th, 2013, 09:36 PM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 313 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 15 h 8 m 35 sec
Reputation Power: 5
Ah. Thanks for the clarity.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > PHP-DB - Cross reference MySQL table for SELECT?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap