Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004

    Question Unanswered: 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 = && trips.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!

  2. #2
    Join Date
    Apr 2002
    Toronto, Canada
    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
    SELECT ...
      FROM trips
      JOIN locations
        ON = trips.locationid 
      JOIN salesmen
        ON = trips.salesmen_id
     WHERE trips.client_name = 'Mr. Jones'
    the third step is to figure out which columns you want in the SELECT clause | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2004
    Thank you! It worked perfectly, of course

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts