Skip to content

Order By in Union Nested selects

I have two really long selects that are both nested How can I order these (both queries combined into one table results) by NewestMessage which is a type of datetime? Answer I would slightly alter your query to: I am basically replacing your union of tuples to a subquery on a union query, using an ORDER BY wi…

Regexp search SQL query fields

I have a repository of SQL queries and I want to understand which queries use certain tables or fields. Let’s say I want to understand what queries use the email field, how can I write it? Example SQL …

SQL Remove all leading zeros

My join returns null because I am not able to remove the leading zeros. Basically, I am trying to replace the pol.Policy_Number with src.Policy_Number for a large number of policies. Is there a way I can remove the leading 0s in the ON statement for src.Policy_Number? I think Padding is needed, but I am new t…

addition within sum case when

How to sum all the customers in DS01,02,03 into DS? select sum(case when Ticket=’DS01′ OR ‘DSO2’ OR ‘DS03′ THEN customer ELSE 0 END) AS DS sum(case when Ticket=’MSO2’ OR ‘MS03’ THEN customer ELSE 0 END) AS MS from table group by ticket unsure how to …