3

I have a following query with subquery that returns no result

SELECT 'Message'
FROM message
WHERE ID in (
SELECT 'Message_id'
FROM user_message
WHERE 'status' =false )

Data in both tables is present. What could be the problem?

2
  • It should be select message from message where id in ( select message_id from user_message where status = false ). No single quotes but can have back ticks on column names. Commented Jun 14, 2014 at 6:22
  • @t.niese: I know that. But I don't think it is the OP's intention. OP unknowingly might have put that. See similar usage on other columns as well. Commented Jun 14, 2014 at 6:30

2 Answers 2

2

Why are you using a sub-query?

Why not

SELECT Message
FROM message JOIN user_message ON ID = Message_id
WHERE status = false

Seems simpler

Sign up to request clarification or add additional context in comments.

2 Comments

back-ticks should replace single quotes.
@Ravinder - I know. missed some
1

You quoted the fields. Either do not quote the fields, or escape your fields with tick like this

SELECT `Message`
FROM message
WHERE ID in (
  SELECT `Message_id`
  FROM user_message
  WHERE `status` =false )

1 Comment

I prefer this solution. It will not generate duplicates if there are multiple matches in user_message.

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.