0

I am really new to SQL & it would be really helpful if somebody can help with one simple query that I am struggling to write.

list ( plid, fid )

files ( fid, filename )

I want to get the fid & filename from the above tables where plid=3. The steps would be 1) Get the fid values from table "list" where plid=x 2) Get the filename from "files" for all the matched fid in table "list".

4
  • You should use JOIN clause. It is easy. Try by yourself. Commented Sep 22, 2014 at 10:54
  • Could you please show what you've tried so far, and where it went wrong? It encourages others to help if you show your own efforts and where exactly you are stuck/which bits you don't understand. Commented Sep 22, 2014 at 10:54
  • Work through a good tutorial liek this one: sqlzoo.net/wiki/The_JOIN_operation Commented Sep 22, 2014 at 10:59
  • Thanks for the tutorial. I will definitely take a look at this today. Time was short & I needed an answer quick. Commented Sep 22, 2014 at 11:08

1 Answer 1

1

That is exactly where you need a JOIN statement:

SELECT list.fid, files.filename FROM list INNER JOIN files ON files.fid = list.fid WHERE files.plid = 3
Sign up to request clarification or add additional context in comments.

4 Comments

Yeah, it is very useful for his understandings.
Write a better answer. Seriously, joins are so fundamental, a very quick search on google or clicking on one of the related questions on the side will tell him all he needs to know. I just lead him in the right direction.
You didn't understand my sarcasm. I mean, he have to write query by himself, without your direct answer. And where is your lead him? :)
Thanks Ke Vin. It worked. Regarding the query that I had done so far, SELECT list.fid, files.filename FROM list INNER JOIN files ON plid=3 and I was unsure about how to put the list.fid=files.fid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.