SQL queries are used to retrieve data from databases. Here are some basic SQL queries with examples:
Example:
Consider a table named "customers" with the following data:
- Now, let's use the basic SQL queries to retrieve data from this table:
- SELECT:
The following query retrieves all data from the "customers" table:
SELECT * FROM customers.
Result:
The following query retrieves all data from the "customers" table where the age is greater than 25:
SELECT * FROM customers WHERE age > 25.
Here is the result:
3. ORDER BY:
The following query retrieves all data from the "customers" table and sorts the result set in descending order of age:
SELECT * FROM customers ORDER BY age DESC.
Here is the result:
4. DISTINCT:
The following query retrieves all distinct ages from the "customers" table:
SELECT DISTINCT age FROM customers.
Here is the result:
5. LIMIT:
The following query retrieves the first two rows from the "customers" table:
SELECT * FROM customers LIMIT 2.
0 Comments