cross table mysql logic problem...

Posted on 2009-04-20
Last Modified: 2012-05-06
Hi, I have 2 tables, one containing jobs and the other locations.
the jobs have a start and stop location field using the keyid of the locations.

key  start stop
1:     2      3

key  description
1:     test1
2:     test2
3:     test3

What i want is to return:
job id:1 start:test2 stop:test

Hope that makes sense, only need the query..

Can anyone help please??
Question by:ewan69
    LVL 10

    Accepted Solution

    You need to double join the location table:

    select j.key, l1.description as start, l2.description as stop
    from job j, location l1, location l2
    where j.start = l1.key
    and j.stop = l2.key

    Open in new window


    Author Comment

    Hi mahome,

    Thanks for the quick reply. Works thanks, spent a good couple of hours trying to work it out...



    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now