0

I'm doing an inner join on a table like this:

SELECT * 
FROM  patient p
INNER JOIN 
    vaccine v
ON 
    p.vaccine_id =  v.id 

The condition f.vac_1 = mv.id might not been satisfied in the case where a person have not been vaccinated. In such case, I don't want to ignore the row, but instead of displaying the vaccine name (which is the purpose of the inner join) to display an emtpy string.

How can this be done ?

Example

Table vaccinne

id name
1 Moderna
2 Comirnaty
3 Janssen

Table patient

id name vaccine_id
1 john 1
2 kermit 2
3 jessica

I'm looking for a query to produce:

id name vaccine_id
1 john Moderna
2 kermit Comirnaty
3 jessica
2
  • What row? Sample data and desired results would help. Commented Jun 12, 2021 at 17:08
  • @GordonLinoff Ok, will add now Commented Jun 12, 2021 at 17:09

1 Answer 1

1

If I understand correctly, you want a left join starting with foo:

SELECT * 
FROM foo f LEFT JOIN
     vac v 
     ON f.vac_1 =  mv.id 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, it work. Much appreciated!

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.