Last active
May 2, 2024 23:20
-
-
Save jxu/848f7452c60ae5aaf82bcb32aad9530d to your computer and use it in GitHub Desktop.
Specifically for T-SQL, probably for other SQLs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Syntax order | |
-- https://learn.microsoft.com/en-us/sql/t-sql/queries/select-transact-sql | |
WITH cte AS (cte_query) | |
SELECT cols | |
FROM table | |
WHERE cond | |
GROUP BY col | |
HAVING cond | |
WINDOW window_expr | |
ORDER BY col | |
-- Logical execution order | |
-- https://learn.microsoft.com/en-us/sql/t-sql/queries/select-transact-sql#logical-processing-order-of-the-select-statement | |
FROM | |
ON | |
JOIN | |
WHERE | |
GROUP BY | |
HAVING | |
SELECT | |
DISTINCT | |
ORDER BY | |
TOP | |
-- Check column unique | |
-- Not considering duplicate NULLs | |
-- https://stackoverflow.com/questions/26199765/sql-query-to-determine-that-values-in-a-column-are-unique | |
SELECT COUNT(col), COUNT(distinct col) FROM table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment