Choose output expressions
Return only columns and calculations the consumer needs.
CodeBhavyaSELECT student_id,
name AS student_name,
cgpa
FROM students;Return only columns and calculations the consumer needs.
AS student_name labels an output expression; it does not rename stored data.
FROM students supplies candidate rows.
It exposes unnecessary columns, couples code to schema order and increases data transfer.
credits * fee AS total_feeA result column may be computed without changing stored values.
SELECT DISTINCT branch, statusDuplicate combinations of all selected expressions are removed.
= <> < <= > >=Compare compatible values. SQL uses =, not ==.
branch = 'AIML' AND cgpa >= 8Both conditions must be TRUE.
branch = 'AIML' OR branch = 'CSE'At least one condition must be TRUE.
NOT status = 'WITHDRAWN'Negates a predicate but preserves UNKNOWN as UNKNOWN.
WHERE branch = 'AIML'
OR branch = 'CSE' AND cgpa >= 9meansWHERE branch = 'AIML'
OR (branch = 'CSE' AND cgpa >= 9)AND is normally evaluated before OR. Use parentheses to make the business rule visible rather than relying on memory.
name LIKE 'A%'% matches zero or more characters; _ matches exactly one. Case sensitivity is product and collation dependent.
branch IN ('AIML', 'CSE')Expresses membership more clearly than repeated equality joined with OR.
cgpa BETWEEN 8 AND 9Includes both boundaries. It is equivalent to cgpa >= 8 AND cgpa <= 9.
branch NOT IN ('ECE', 'IT')Be careful when the compared value or list contains NULL; UNKNOWN can remove unexpected rows.
'A%' begins with A'%an%' contains an'_i%' second character is i'____' exactly four charactersWHERE mentor_id = NULLMatches no rows through TRUEOrdinary comparison with NULL produces UNKNOWN.
WHERE mentor_id IS NULLMatches rows with missing mentor_idIS NULL is the dedicated nullness predicate.
COALESCE(cgpa, 0)Returns the first non-NULL argument. Use a replacement only when its meaning is valid.
ORDER BY cgpa NULLS LASTUseful where supported; default NULL placement and syntax vary by DBMS.
FALSE and UNKNOWN are both excluded.
SELECT student_id, name, cgpa
FROM students
ORDER BY cgpa DESC, student_id ASC
LIMIT 5 OFFSET 10;student_id breaks ties between equal CGPA values.
ASC is commonly the default; write DESC when highest values should lead.
LIMIT/OFFSET, FETCH/OFFSET and TOP are dialect families. Deep OFFSET pages can be expensive or unstable under changing data.
Include a unique final sort key so the same rows do not move arbitrarily between pages.
SELECT name, cgpa,
CASE
WHEN cgpa IS NULL THEN 'Pending'
WHEN cgpa >= 9 THEN 'Outstanding'
WHEN cgpa >= 8 THEN 'Strong'
ELSE 'Developing'
END AS performance
FROM students;Choose result columns, combine up to two filters, sort and limit. The generated SQL and every logical-stage row count update together.
Select a predicate to see which rows become TRUE, FALSE or UNKNOWN.
Mark this level when you can predict which rows and columns a SELECT returns before running it.
Saved in this browser only.