Learn how to a build a cloud-first strategyRegister Now


cross table mysql logic problem...

Posted on 2009-04-20
Medium Priority
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

mahome earned 500 total points
ID: 24184399
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

ID: 24184649
Hi mahome,

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



Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month20 days, 14 hours left to enroll

810 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