Skip to content

Instantly share code, notes, and snippets.

@tylergets
Created September 29, 2023 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylergets/acbacd2999b6c9b59de5d1f66802fa95 to your computer and use it in GitHub Desktop.
Save tylergets/acbacd2999b6c9b59de5d1f66802fa95 to your computer and use it in GitHub Desktop.
SELECT
"Order".id,
C.name,
A.line1,
A.line2,
A.city,
A.zip,
S.name,
H.name as "hatchery_name",
HA.line1 as "hatchery_line1",
HA.line2 as "hatchery_line2",
HA.city as "hatchery_city",
HS.name as "hatchery_state",
HA.zip as "hatchery_zip"
FROM "Order"
LEFT JOIN "Customer" C on "Order"."customerId" = C.id
LEFT JOIN "Hatchery" H on C."hatcheryId" = H.id
LEFT JOIN "Address" HA on H."addressId" = HA.id
LEFT JOIN "Address" A on "Order"."shippingAddressId" = A.id
LEFT JOIN "State" S on A."stateId" = S.id
LEFT JOIN "State" HS on HA."stateId" = HS.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment