0

I have this query (MYSQL):

    SELECT agent.name,agency.title FROM agent, agency WHERE agent.id = "1"
    AND agent.titleid = agency.titleid

This will give me a record with the name and title, however if the second condition fail, the whole query will fall and it will display nothing.

Is it possible that if let's say the title cannot be found in agency table, then only display out the name and leave the title column blank.

What is the query to be able to do that?

0

2 Answers 2

0

Try:

SELECT agent.name,agency.title FROM agent
LEFT JOIN agency ON agent.titleid = agency.titleid
WHERE agent.id = "1"
1
  • You are much welcome @user1841098. GOD bless in your quest to learn more.
    – Edper
    Commented Jun 7, 2013 at 12:47
0

I think you can achieve this with a LEFT JOIN query

SELECT a.name, b.title 
FROM agent a
LEFT JOIN agency b 
ON a.titleid = b.titleid
WHERE a.id = '1'

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.