Lob City
Lob City

Reputation: 87

How to query a table and display NULL on the joined table if it does not meet the filter?

Here's my data:

Vacation -has Organizer column

Itinerary

ItineraryPayment - this is a cross table with Itinerary and LK_Payment. just assume that it's the name -has PaymentStatus

What I want to do is to be able to select the organizer column in Vacation and if the ItineraryPayment will be null or has a value depending if the Vacation has an Itinerary linked to it. How do I do this?

Thanks in advance!

Upvotes: 0

Views: 90

Answers (2)

Murtaza
Murtaza

Reputation: 3065

refer this URL for Joins in SQL server.

JOINS IN SQL

You will get the NULL values using.

Left Join or Right Join

Upvotes: 0

Kyra
Kyra

Reputation: 5407

Based on what you said:

select v.organizer, (cases i.vacation_id is null then i.value else null end)
from Vacation as v
left join itinerary as i
   on v.vacation_id = i.vacation_id

Upvotes: 1

Related Questions