-1

Table: tpayments date job_no item amount id

Table: tjobs
job_no job_name value start_date completion_date duration_mths type_no manager_no client_no location status notes

I tried using this:

SELECT * from tpayments LEFT JOIN tjobs ON tjobs.job_no=tjobs.job_no WHERE location = 'Qatar';

Sorry but, I'm currently studying linking tables through SQL.

All I want is just to display the row of payments if the location is in Qatar, based on the tjobs table.

Thanks

caleb.breckon
  • 1,336
  • 18
  • 42
  • What's the error/unexpected output you are receiving? – TheWolf Oct 09 '13 at 22:32
  • It looks like you would really benefit from reading this [Q&A that I wrote for times just like this](http://stackoverflow.com/questions/12475850/how-can-an-sql-query-return-data-from-multiple-tables) it covers off joins of tables, selecting only specific data and a whole bunch more. Do yourself a favour and have a read :) – Fluffeh Oct 09 '13 at 22:37

3 Answers3

2

Your query is joining tjobs to itself. you need to join it to tpayments

 ON tjobs.job_no = tpayments.job_no
caleb.breckon
  • 1,336
  • 18
  • 42
2

try this

SELECT t.date, t.job_no, t.item, t.amount_id from tpayments t
LEFT JOIN tjobs ts ON t.job_no=ts.job_no 
WHERE ts.location = 'Qatar';
Osama Jetawe
  • 2,697
  • 6
  • 24
  • 40
1
SELECT p.*
FROM tpayments AS p
LEFT JOIN tjobs AS j
ON p.job_no = j.job_no
WHERE j.location = 'Qatar';
Andris
  • 5,853
  • 3
  • 28
  • 34