If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Problems in my WHERE clause :(

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-09-09, 10:53
mturner mturner is offline
Registered User
 
Join Date: Feb 2004
Posts: 41
Question Problems in my WHERE clause :(

I have three tables: trips, salesmen, locations

In "trips" i have the clients name, the salesman's ID number and the location ID number.

I am querying the DB for a specific client name, and want to show the results, but with the actual names of the locations and salesmen not their ID numbers.

So here is my query that is NOT working:

SELECT trips.*, locations.*, salesmen.*
FROM trips, locations, salesmen
WHERE trips.locationid = locations.id && trips.salesmen_id = salesmen.id

This is returning a massive amount of data that repeats itself. And I happen to know, for the client I am querying their are 7 trips.

What do I do to get it to "convert" the ID numbers in trips to their full names stored in "locations" and "salesmen"?

Please help, and thank you!
Reply With Quote
  #2 (permalink)  
Old 12-09-09, 11:10
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
first thing you should do is rewrite the query to use JOIN syntax

secondly, if you are "querying the DB for a specific client name" then you should put that into the WHERE clause
Code:
SELECT ...
  FROM trips
INNER
  JOIN locations
    ON locations.id = trips.locationid 
INNER
  JOIN salesmen
    ON salesmen.id = trips.salesmen_id
 WHERE trips.client_name = 'Mr. Jones'
the third step is to figure out which columns you want in the SELECT clause
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 12-09-09, 16:20
mturner mturner is offline
Registered User
 
Join Date: Feb 2004
Posts: 41
Thank you! It worked perfectly, of course
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On