0

I have table named store_products in my DB.

Below Query Returns me 1

SELECT u_id FROM store_products WHERE p_id=1

I want to Get Company Details Using Above Return 1 with that Query.

So I wrote Below Query But It's not working for me.

SELECT * FROM reg_companies WHERE u_id = ('SELECT u_id FROM store_products WHERE p_id=1')

Kindly Help Me.

2
  • 1
    Don't put the sub-query in quotes... Commented Mar 11, 2017 at 16:50
  • Thanks Bro ........ !! Commented Mar 11, 2017 at 16:58

1 Answer 1

2

I guess you want to do this :

SELECT * FROM reg_companies 
WHERE u_id IN (SELECT u_id FROM store_products WHERE p_id=1)

You had surrounded your nested query with quotes, which turned it into an non meaningful string.

A better approach would be a join between the 2 tables

SELECT C.* 
FROM reg_companies C
INNER JOIN store_products P ON C.u_id=P.u_id
WHERE P.p_id=1
Sign up to request clarification or add additional context in comments.

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.