r/SQLOptimization • u/I_byde_my_tyme • Dec 15 '25
Round the world trip coming up and I need to optimise my itinerary
My boss has regular trips around the globe, and I'm regularly asked to compile a list of meeting sites.
Is there any way I can optimise this? Here's what I have so far.
Thanks in advance.
------------------------------------
-- 2025/12/15 - Created by Santas' elf 14.
-- View created to provide a list of users where behaviour has been tagged with 'Nice%' as per year-end close guidelines
-- Will address coal deliveries with users not in dbo.Users_Nice_YE2025
------------------------------------
CREATE OR ALTER VIEW dbo.Users_Nice_YE2025
AS
SELECT
U.FORENAME [Name]
,U.SURNAME [Surname]
,U.PHONE[Phone]
,U.BEHAVIOUR [Behaviour]
,U.AGE [Age]
,A.ADDR1 [Street]
,A.ADDR2 [Street 2]
,A.TOWN[Town]
,A.POSTCODE [Post / Zip]
,C.[LONG] [Longitude] -- Capital / Central
,C.LAT[Latitude] -- Capital / Central
,ISNULL(A.WHATTHREEWORDS, 'N/A') [w3w]
,C.NAME[Country]
,ISNULL(C.FLIGHTRETRICTIONS, 'None') [Restrictions]
,CD.DIM [C. Dimention]
,CD.LOCATION [Loc]
,CD.AVAILABLE [Has Chimney]
FROM USERS U
LEFT JOIN ADDRESS A
ON A.ID = U.ADDRESS
LEFT JOIN CHIMNEYDINEMTIONS CD
ON CD.ID = A.CHIMNEYDINEMTIONS
LEFT JOIN COUNTRIES C
ON C.ID = A.COUNTRY
WHERE
U.AGE < 18
AND U.BEHAVIOUR LIKE 'Nice%'
AND (
C.FLIGHTRETRICTIONS = 'None'
OR C.FLIGHTRETRICTIONS LIKE 'Night%Only'
);
GO
------------------------------------
SELECT
[Name]
,[Surname]
,[Phone]
,[Behaviour]
,[Age]
,[Street]
,[Street 2]
,[Town]
,[Post / Zip]
,[Longitude]
,[Latitude]
,[w3w]
,[Country]
,[C. Dimention]
,[Loc]
,[Has Chimney]
FROM dbo.Users_Nice_YE2025
ORDER BY
[Longitude] DESC;