1

I'm working on a script that requires gathering information from a few different tables, and I just want to know if there is a way to handle my situation without running multiple queries. I'm a little new to mySQL and this example would really help with future situations.

tbl1 = foo_id, bar_id
tbl2 = foo_id, bool, num_id

From tbl1 I need to grab the foo_id where the bar_id = (random number), and then with that foo_id grab the num_id from tbl2 where the bool = 1.

Thanks in advance!

1
  • 2
    Have you learned about JOINs yet? I think you should look into INNER JOINS in MySQL Commented May 13, 2014 at 17:48

2 Answers 2

1

You can try that :

SELECT t2.num_id
FROM tbl1 t1, tbl2 t2
WHERE t1.bar_id = number
    AND t1.foo_id = t2.foo_id
    AND t2.bool = 1
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, I get it. Thank you!!
1

you try using joins ,

SELECT t2.num_id
FROM tbl1 t1 INNER JOIN tbl2 t2 ON t1.foo_id = t2.foo_id
WHERE t1.bar_id = number
AND t2.bool = 1

Comments

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.