sql >> Database teknologi >  >> RDS >> Sqlserver

SQL Server-forespørgsel:Brug af JOIN til at inkludere NULL-værdier

For at returnere eller producere NULL værdier, du skal bruge LEFT JOIN s.

Så din forespørgsel bør være noget i stil med:

SELECT 
     a.ReservationStayID AS 'Reservation Id'
    ,a.PMSConfirmationNumber AS 'PMS No'
    ,a.CreatedOn AS 'Date Created'
    ,a.ArrivalDate AS 'Date of Arrival'
    ,a.DepartureDate AS 'Date of Departure'
    ,a.TAProfileID AS 'TA Id'
    ,a.StatusCode AS 'Status'
    ,b.PropertyCode AS 'Hotel'
    ,c.NAME AS 'Travel Agency'
    ,c.CountryCode AS 'Market Code'
    ,d.CountryName AS 'Mkt'
FROM ReservationStay a
    INNER JOIN GuestStaySummary b ON a.ReservationStayID = b.ReservationStayID
    LEFT JOIN TravelAgency c ON a.TAProfileID = c.TravelAgencyID
    LEFT JOIN Market d ON c.CountryCode = d.CountryCode



  1. Laravel - Querybuilder med join og concat

  2. Sådan bruger du array_agg() til varchar[]

  3. Lagring af uploadede billeder:Skal det gemmes på serveren eller i databasen?

  4. mysqldump enkelt tabel fra python underproces