Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
19 views

SQL 1

The document describes different types of SQL queries including selecting data from tables, filtering rows with conditions, aggregating data, sorting results, combining result sets from multiple queries, and pattern matching.

Uploaded by

Laks A
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

SQL 1

The document describes different types of SQL queries including selecting data from tables, filtering rows with conditions, aggregating data, sorting results, combining result sets from multiple queries, and pattern matching.

Uploaded by

Laks A
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

SELECT c1, c2 FROM t;

Query data in columns c1, c2 from a table


SELECT * FROM t;
Query all rows and columns from a table
SELECT c1, c2 FROM t
WHERE condition;
Query data and filter rows with a condition
SELECT DISTINCT c1 FROM t
WHERE condition;
Query distinct rows from a table
SELECT c1, aggregate(c2)
FROM t
GROUP BY c1;
Group rows using an aggregate function
SELECT c1, aggregate(c2)
FROM t
GROUP BY c1
HAVING condition;
Filter groups using HAVING clause
SELECT c1, c2 FROM t
ORDER BY c1ASC [DESC];
Sort the result setin ascending or descending order
SELECT c1, c2 FROM t1
UNION [ALL]
SELECT c1, c2 FROM t2;
Combine rows from two queries
SELECT c1, c2 FROM t1
INTERSECT
SELECT c1, c2 FROM t2;
Return the intersection of two queries
SELECT c1, c2 FROM t1
MINUS
SELECTc1, c2 FROM t2;
Subtract a result set from another result set
SELECT c1, c2 FROM t1
WHERE c1[NOT] LIKE pattern;
Query rows using pattern matching %, _
SELECT c1, c2 FROM t
WHERE c1 [NOT] IN value_list;
Query rows in a list
SELECT c1, c2 FROM t
WHERE c1 BETWEEN low AND high;
Query rows between two values
SELECT c1, c2 FROM t
WHERE c1 IS [NOT] NULL;
Check if values in a table is NULL or not
QUERYING

You might also like