Ticker

6/recent/ticker-posts

SQL Tutorials For Beginners - 1

 

SQL Intro

Introduction to SQL




SQL (Structured Query Language) is a programming language designed for managing and manipulating relational databases. It provides a set of commands and syntax for performing various operations on databases, such as querying, inserting, updating, and deleting data.

Benefits of Using SQL

  • SQL is widely adopted and supported by most relational database management systems (RDBMS).
  • It offers a standardized and consistent way to interact with databases.
  • SQL is declarative, meaning you specify what data you want rather than how to get it, allowing the database engine to optimize the query execution.
  • It provides a high-level abstraction, allowing users to work with data without needing to understand the underlying storage details.

SQL Syntax

Basic SQL Syntax

SQL statements are written using a specific syntax. Here's a basic template of an SQL statement:

sql
SELECT column1, column2, ... FROM table_name WHERE condition
  • SELECT specifies the columns you want to retrieve from the table.
  • FROM specifies the table from which you want to retrieve the data.
  • WHERE (optional) specifies the condition(s) that the data must meet to be included in the result set.

Example

sql
SELECT * FROM customers WHERE age > 30;

In this example, the statement selects all columns (*) from the table named customers, but only includes rows where the age column is greater than 30.

SQL Select

The SELECT Statement

The SELECT statement is used to retrieve data from one or more tables in a database. It allows you to specify the columns you want to retrieve and the table(s) from which you want to retrieve the data.

Syntax

sql
SELECT column1, column2, ... FROM table_name;
  • column1, column2, ... specifies the columns you want to retrieve. Use * to select all columns.
  • table_name specifies the table from which you want to retrieve the data.

Example

sql
SELECT first_name, last_name, email FROM customers;

In this example, the statement selects the first_name, last_name, and email columns from the customers table.

SQL Select Distinct

The SELECT DISTINCT Statement

The SELECT DISTINCT statement is used to retrieve unique values from a specific column in a table. It eliminates duplicate values and returns only distinct values.

Syntax

sql
SELECT DISTINCT column_name FROM table_name;
  • column_name specifies the column from which you want to retrieve distinct values.
  • table_name specifies the table from which you want to retrieve the data.

Example

sql
SELECT DISTINCT country FROM customers;

In this example, the statement selects distinct values from the country column in the customers table, eliminating any duplicate values.

SQL Where

The WHERE Clause

The WHERE clause is used to filter the rows returned by an SQL query based on specified conditions. It allows you to retrieve only the rows that meet certain criteria.

Syntax

sql
SELECT column1, column2, ... FROM table_name WHERE condition;
  • condition specifies the condition(s) that the data must meet to be included in the result set.

Example

sql
SELECT * FROM orders WHERE total_amount > 1000;

In this example, the statement selects all columns from the orders table but only includes rows where the total_amount column is greater than 1000.

SQL And, Or, Not

Logical Operators: AND, OR, NOT

Logical operators (AND, OR, NOT) are used in the WHERE clause to combine multiple conditions to create more complex filtering criteria.

  • AND operator returns true if all the conditions separated by AND are true.
  • OR operator returns true if at least one of the conditions separated by OR is true.
  • NOT operator reverses the result of the following condition, returning true if the condition is false and vice versa.

Syntax

sql
SELECT column1, column2, ... FROM table_name WHERE condition1 AND condition2 ... OR conditionN;

Example

sql
SELECT * FROM customers WHERE age > 30 AND country = 'USA';

In this example, the statement selects all columns from the customers table where the age column is greater than 30 and the country column is equal to 'USA'.

SQL Order By

The ORDER BY Clause

The ORDER BY clause is used to sort the result set of an SQL query based on one or more columns. It allows you to specify the order in which the rows should be returned.

Syntax

sql
SELECT column1, column2, ... FROM table_name ORDER BY column1 [ASC|DESC], column2 [ASC|DESC], ...;
  • column1, column2, ... specifies the columns you want to use for sorting.
  • ASC (default) sorts the result set in ascending order.
  • DESC sorts the result set in descending order.

Example

sql
SELECT * FROM products ORDER BY price DESC;

In this example, the statement selects all columns from the products table and orders the result set by the price column in descending order.

SQL Insert Into

The INSERT INTO Statement

The INSERT INTO statement is used to insert new rows into a table. It allows you to specify the values you want to insert for each column.

Syntax

sql
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
  • table_name specifies the table into which you want to insert the data.
  • (column1, column2, ...) specifies the columns into which you want to insert values. This part is optional if you're inserting values into all columns.
  • VALUES (value1, value2, ...) specifies the values you want to insert. The number of values must match the number of columns.

Example

sql
INSERT INTO customers (first_name, last_name, email) VALUES ('John', 'Doe', 'john.doe@example.com');

In this example, the statement inserts a new row into the customers table with the values 'John' for the first_name column, 'Doe' for the last_name column, and 'john.doe@example.com' for the email column.

SQL Null Values

Null Values in SQL

In SQL, a null value represents the absence of a value in a column. It indicates that the data is missing or unknown. Null values can be assigned to any data type.

Handling Null Values

  • To check for null values, you can use the IS NULL or IS NOT NULL operators in the WHERE clause.
  • When inserting or updating data, you can explicitly set a column to a null value by using the NULL keyword.
  • Functions like COALESCE and IFNULL can be used to substitute a null value with a specific value.

Example

sql
SELECT * FROM employees WHERE salary IS NULL;

In this example, the statement selects all columns from the employees table where the salary column is null.

SQL Update

The UPDATE Statement

The UPDATE statement is used to modify existing records in a table. It allows you to change the values of one or more columns in one or more rows.

Syntax

sql
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
  • table_name specifies the table in which you want to update records.
  • column1 = value1, column2 = value2, ... specifies the columns and their new values that you want to update.
  • condition specifies the condition(s) that the rows must meet to be updated.

Example

sql
UPDATE customers SET status = 'Inactive' WHERE last_purchase_date < '2022-01-01';

In this example, the statement updates the status column in the customers table to 'Inactive' for all rows where the last_purchase_date is earlier than January 1, 2022.

SQL Delete

The DELETE Statement

The DELETE statement is used to delete existing records from a table. It allows you to remove one or more rows that meet specified conditions.

Syntax

sql
DELETE FROM table_name WHERE condition;
  • table_name specifies the table from which you want to delete records.
  • condition specifies the condition(s) that the rows must meet to be deleted.

Example

sql
DELETE FROM products WHERE quantity < 10;

In this example, the statement deletes all rows from the products table where the quantity is less than 10.

SQL Select Top

The SELECT TOP Clause

The SELECT TOP clause is used to retrieve a specific number of rows from the result set of an SQL query. It allows you to limit the number of rows returned.

Syntax (for MySQL and PostgreSQL)

sql
SELECT column1, column2, ... FROM table_name LIMIT number_of_rows;
  • number_of_rows specifies the maximum number of rows to be returned.

Syntax (for SQL Server)

sql
SELECT TOP number_of_rows column1, column2, ... FROM table_name;
  • number_of_rows specifies the maximum number of rows to be returned.

Example

sql
SELECT TOP 5 * FROM customers;

In this example, the statement selects all columns from the customers table and returns only the top 5 rows.

SQL Min and Max

The MIN and MAX Functions

The MIN and MAX functions are used to retrieve the minimum and maximum values from a column, respectively.

Syntax

sql
SELECT MIN(column_name) FROM table_name; 
SELECT MAX(column_name) FROM table_name;
  • column_name specifies the column from which you want to retrieve the minimum or maximum value.
  • table_name specifies the table from which you want to retrieve the data.

Example

sql
SELECT MIN(price) FROM products;

In this example, the statement retrieves the minimum value from the price column in the products table.

sql
SELECT MAX(quantity) FROM products;

In this example, the statement retrieves the maximum value from the quantity column in the products table.

SQL Count, Avg, Sum

The COUNT, AVG, and SUM Functions

The COUNT, AVG, and SUM functions are used to perform calculations on columns in a table.

  • COUNT returns the number of rows that match a specified condition or the total number of rows in a table.
  • AVG returns the average value of a numeric column.
  • SUM returns the sum of values in a numeric column.

Syntax

sql
SELECT COUNT(column_name) FROM table_name WHERE condition
SELECT AVG(column_name) FROM table_name WHERE condition
SELECT SUM(column_name) FROM table_name WHERE condition;
  • column_name specifies the column on which you want to perform the calculation.
  • table_name specifies the table from which you want to retrieve the data.
  • condition (optional) specifies the condition(s) that the rows must meet to be included in the calculation.

Example

sql
SELECT COUNT(*) FROM orders; 
SELECT AVG(price) FROM products WHERE category = 'Electronics'
SELECT SUM(quantity) FROM products WHERE category = 'Clothing';

In these examples, the statements calculate the total number of rows in the orders table, the average price of products in the 'Electronics' category, and the sum of the quantity for products in the 'Clothing' category, respectively.

SQL Like

The LIKE Operator

The LIKE operator is used in the WHERE clause to search for a specified pattern in a column. It is commonly used with wildcard characters to perform pattern matching.

Syntax

sql
SELECT column1, column2, ... FROM table_name WHERE column_name LIKE pattern;
  • column1, column2, ... specifies the columns you want to retrieve.
  • table_name specifies the table from which you want to retrieve the data.
  • column_name specifies the column in which you want to search for the pattern.
  • pattern specifies the pattern to search for. It can include wildcard characters % (matches any string of any length) and _ (matches any single character).

Example

sql
SELECT * FROM customers WHERE first_name LIKE 'J%';

In this example, the statement selects all columns from the customers table where the first_name starts with the letter 'J'.

SQL Wildcards

Wildcard Characters in SQL

Wildcard characters are special characters used in combination with the LIKE operator to match patterns in a column.

  • % (percent sign) matches any string of any length.
  • _ (underscore) matches any single character.

Example

sql
SELECT * FROM products WHERE product_name LIKE '%book%';

In this example, the statement selects all columns from the products table where the product_name contains the word 'book', regardless of the characters before or after it.

SQL In

The IN Operator

The IN operator is used in the WHERE clause to specify multiple values for a column. It allows you to filter rows based on a list of predefined values.

Syntax

sql
SELECT column1, column2, ... FROM table_name WHERE column_name IN (value1, value2, ...);
  • column1, column2, ... specifies the columns you want to retrieve.
  • table_name specifies the table from which you want to retrieve the data.
  • column_name specifies the column on which you want to apply the filter.
  • (value1, value2, ...) specifies the list of values that the column should match.

Example

sql
SELECT * FROM products WHERE category IN ('Electronics', 'Appliances', 'Furniture');

In this example, the statement selects all columns from the products table where the category is either 'Electronics', 'Appliances', or 'Furniture'.

SQL Between

The BETWEEN Operator

The BETWEEN operator is used in the WHERE clause to specify a range of values for a column. It allows you to filter rows based on values that fall within a specified range.

Syntax

sql
SELECT column1, column2, ... FROM table_name WHERE column_name BETWEEN value1 AND value2;
  • column1, column2, ... specifies the columns you want to retrieve.
  • table_name specifies the table from which you want to retrieve the data.
  • column_name specifies the column on which you want to apply the filter.
  • value1 and value2 specify the range of values.

Example

sql
SELECT * FROM products WHERE price BETWEEN 1000 AND 2000;

In this example, the statement selects all columns from the products table where the price falls between 1000 and 2000 (inclusive).

SQL Aliases

Table and Column Aliases

Aliases are used to give a temporary name to a table or column in an SQL query. They are often used to make column names more readable or to avoid naming conflicts.

  • Table aliases provide a shorter name for a table in a query.
  • Column aliases provide a temporary name for a column in the result set.

Syntax

sql
SELECT column_name AS alias_name FROM table_name AS alias_name; 
SELECT column_name1, column_name2 AS alias_name2, ... FROM table_name;
  • column_name specifies the column you want to select.
  • table_name specifies the table from which you want to select.
  • alias_name specifies the temporary name you want to assign to the table or column.

Example

sql
SELECT c.first_name, c.last_name, o.order_date FROM customers AS c JOIN orders AS o ON c.customer_id = o.customer_id; 
SELECT product_name AS Name, price AS Price FROM products;

In these examples, the statements select columns from tables using aliases. In the first example, the customers table is aliased as c, and the orders table is aliased as o. In the second example, the product_name column is aliased as Name, and the price column is aliased as Price.

SQL Joins

Joins in SQL

Joins are used to combine rows from two or more tables based on related columns. They allow you to retrieve data from multiple tables in a single query.

  • INNER JOIN returns only the rows that have matching values in both tables.
  • LEFT JOIN returns all the rows from the left table and the matching rows from the right table.
  • RIGHT JOIN returns all the rows from the right table and the matching rows from the left table.
  • FULL JOIN returns all the rows from both tables, including unmatched rows.
  • CROSS JOIN returns the Cartesian product of the two tables.

Syntax

sql
SELECT column1, column2, ... FROM table1 JOIN table2 ON table1.column_name = table2.column_name; 
SELECT column1, column2, ... FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name; 
SELECT column1, column2, ... FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name; SELECT column1, column2, ... FROM table1 FULL JOIN table2 ON table1.column_name = table2.column_name; 
SELECT column1, column2, ... FROM table1 CROSS JOIN table2;
  • column1, column2, ... specifies the columns you want to select.
  • table1, table2 specify the tables you want to join.
  • JOIN keyword specifies the type of join you want to perform.
  • ON keyword specifies the join condition.

Example

sql
SELECT customers.customer_id, orders.order_date FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id; 
SELECT customers.customer_id, orders.order_date FROM customers LEFT JOIN orders ON customers.customer_id = orders.customer_id; 
SELECT customers.customer_id, orders.order_date FROM customers RIGHT JOIN orders ON customers.customer_id = orders.customer_id; 
SELECT customers.customer_id, orders.order_date FROM customers FULL JOIN orders ON customers.customer_id = orders.customer_id; SELECT * FROM customers CROSS JOIN orders;

In these examples, the statements perform different types of joins between the customers and orders tables. They select specific columns or all columns from the resulting joined tables.

SQL Self Join

Self Joins in SQL

A self join is a type of join where a table is joined with itself. It is used when you want to combine rows from the same table based on related columns.

Syntax

sql
SELECT column1, column2, ... FROM table1 alias1 JOIN table1 alias2 ON alias1.column_name = alias2.column_name;
  • column1, column2, ... specifies the columns you want to select.
  • table1 specifies the table you want to join with itself.
  • alias1, alias2 specify aliases for the same table.
  • alias1.column_name = alias2.column_name specifies the join condition between the aliases.

Example

sql
SELECT e.employee_id, e.first_name, m.first_name AS manager_name FROM employees e JOIN employees m ON e.manager_id = m.employee_id;

In this example, the statement performs a self join on the employees table. It selects the employee ID, first name of each employee, and the first name of their respective managers.

SQL Union

The UNION Operator

The UNION operator is used to combine the result sets of two or more SELECT statements into a single result set. The UNION operator removes duplicate rows from the combined result set.

Syntax

sql
SELECT column1, column2, ... FROM table1 UNION SELECT column1, column2, ... FROM table2;
  • column1, column2, ... specifies the columns you want to select.
  • table1, table2 specify the tables from which you want to select.

Example

sql
SELECT product_name, price FROM products WHERE category = 'Electronics' UNION SELECT product_name, price FROM products WHERE category = 'Appliances';

In this example, the statement combines the result sets of two SELECT statements using the UNION operator. It selects the product name and price from the products table for the 'Electronics' category and the 'Appliances' category.

SQL Group By

The GROUP BY Clause

The GROUP BY clause is used to group rows in a result set based on one or more columns. It allows you to perform aggregate functions on groups of rows.

Syntax

sql
SELECT column1, aggregate_function(column2), ... FROM table_name GROUP BY column1;
  • column1 specifies the column you want to group by.
  • aggregate_function(column2) specifies the aggregate function you want to perform on the grouped rows.
  • table_name specifies the table from which you want to retrieve the data.

Example

sql
SELECT category, AVG(price) AS avg_price FROM products GROUP BY category;

In this example, the statement groups the rows in the products table by the category column. It calculates the average price for each category using the AVG aggregate function.

SQL Having

The HAVING Clause

The HAVING clause is used to filter groups in a GROUP BY query based on a specified condition. It is similar to the WHERE clause, but it operates on the grouped rows rather than individual rows.

Syntax

sql
SELECT column1, aggregate_function(column2), ... FROM table_name GROUP BY column1 HAVING condition;
  • column1 specifies the column you want to group by.
  • aggregate_function(column2) specifies the aggregate function you want to perform on the grouped rows.
  • table_name specifies the table from which you want to retrieve the data.
  • condition specifies the condition that the groups must meet.

Example

sql
SELECT category, AVG(price) AS avg_price FROM products GROUP BY category HAVING AVG(price) > 1000;

In this example, the statement groups the rows in the products table by the category column. It calculates the average price for each category using the AVG aggregate function. The HAVING clause filters out the groups where the average price is greater than 1000.

SQL Exists

The EXISTS Operator

The EXISTS operator is used in the WHERE clause to check the existence of rows returned by a subquery. It returns true if the subquery returns any rows, and false otherwise.

Syntax

sql
SELECT column1, column2, ... FROM table_name WHERE EXISTS (subquery);
  • column1, column2, ... specifies the columns you want to select.
  • table_name specifies the table from which you want to retrieve the data.
  • subquery specifies the subquery that returns rows to check for existence.

Example

sql
SELECT product_name, price FROM products WHERE EXISTS ( SELECT * FROM orders WHERE orders.product_id = products.product_id );

In this example, the statement selects the product name and price from the products table for the products that have at least one corresponding order in the orders table.

SQL Any, All

The ANY and ALL Operators

The ANY and ALL operators are used in combination with comparison operators to compare a value with a set of values returned by a subquery.

  • ANY operator returns true if the comparison is true for at least one value in the set.
  • ALL operator returns true if the comparison is true for all values in the set.

Syntax

sql
SELECT column1, column2, ... FROM table_name WHERE column_name operator ANY (subquery); 
SELECT column1, column2, ... FROM table_name WHERE column_name operator ALL (subquery);
  • column1, column2, ... specifies the columns you want to select.
  • table_name specifies the table from which you want to retrieve the data.
  • column_name specifies the column on which you want to apply the comparison.
  • operator specifies the comparison operator.
  • subquery specifies the subquery that returns the set of values to compare.

Example

sql
SELECT product_name, price FROM products WHERE price > ANY ( SELECT price FROM products WHERE category = 'Electronics' );

In this example, the statement selects the product name and price from the products table for the products that have a price greater than any price of products in the 'Electronics' category.

SQL Select Into

The SELECT INTO Statement

The SELECT INTO statement is used to create a new table and insert the result set of a SELECT query into the new table. It allows you to quickly create and populate a table based on an existing query.

Syntax

sql
SELECT column1, column2, ... INTO new_table FROM table_name WHERE condition;
  • column1, column2, ... specifies the columns you want to select.
  • new_table specifies the name of the new table to be created.
  • table_name specifies the table from which you want to retrieve the data.
  • condition specifies the condition that the rows must meet to be included in the result set.

Example

sql
SELECT customer_id, first_name, last_name INTO new_customers FROM customers WHERE country = 'USA';

In this example, the statement creates a new table called new_customers and inserts the customer ID, first name, and last name of customers from the customers table who are from the USA.

SQL Insert Into Select

The INSERT INTO SELECT Statement

The INSERT INTO SELECT statement is used to insert data into a table from the result set of a SELECT query. It allows you to copy data from one table to another or insert a subset of data into an existing table.

Syntax

sql
INSERT INTO table_name (column1, column2, ...) 
SELECT column1, column2, ... FROM source_table WHERE condition;
  • table_name specifies the table into which you want to insert the data.
  • (column1, column2, ...) specifies the columns into which you want to insert the data.
  • column1, column2, ... specifies the columns you want to select.
  • source_table specifies the table from which you want to retrieve the data.
  • condition specifies the condition that the rows must meet to be included in the result set.

Example

sql
INSERT INTO new_orders (order_id, order_date, customer_id) 
SELECT order_id, order_date, customer_id FROM orders WHERE order_date >= '2023-01-01';

In this example, the statement inserts the order ID, order date, and customer ID from the orders table into the new_orders table for orders placed on or after January 1, 2023.

SQL Case

The CASE Statement

The CASE statement is used to perform conditional logic in SQL queries. It allows you to define different result expressions based on specified conditions.

Syntax

sql
SELECT column1, CASE WHEN condition1 THEN result1 WHEN condition2 THEN result2 ... ELSE result END AS column_alias FROM table_name;
  • column1 specifies the column you want to select.
  • condition1, condition2, ... specify the conditions to check.
  • result1, result2, ... specify the result expressions for each condition.
  • result (optional) specifies the default result expression when none of the conditions are met.
  • column_alias specifies the alias for the result column.

Example

sql
SELECT product_name, CASE WHEN price < 1000 THEN 'Low' WHEN price >= 1000 AND price < 5000 THEN 'Medium' ELSE 'High' END AS price_category FROM products;

In this example, the statement selects the product name and uses the CASE statement to categorize the products based on their price. The price_category column will contain the values 'Low', 'Medium', or 'High' depending on the price.

SQL Null Functions

NULL Functions in SQL

NULL functions are used to handle NULL values in SQL queries. They provide ways to check for NULL values and perform operations accordingly.

  • IS NULL function checks if a value is NULL.
  • IS NOT NULL function checks if a value is not NULL.
  • COALESCE function returns the first non-NULL value in a list.
  • NULLIF function compares two expressions and returns NULL if they are equal.

Syntax

sql
SELECT column1, column2, ... FROM table_name WHERE column_name IS NULL
SELECT column1, column2, ... FROM table_name WHERE column_name IS NOT NULL
SELECT COALESCE(expression1, expression2, ...) FROM table_name; 
SELECT NULLIF(expression1, expression2) FROM table_name;
  • column1, column2, ... specifies the columns you want to select.
  • table_name specifies the table from which you want to retrieve the data.
  • column_name specifies the column you want to check for NULL values.
  • expression1, expression2, ... specify the expressions or values to evaluate.

Example

sql
SELECT customer_name FROM customers WHERE phone IS NULL; SELECT customer_name FROM customers WHERE email IS NOT NULL
SELECT COALESCE(nickname, first_name, last_name) AS display_name FROM users; 
SELECT NULLIF(quantity, 0) FROM products;

In these examples, the statements use different NULL functions. They select customer names based on phone or email availability, determine the display name for users based on nickname or name columns, and handle NULL quantities by returning NULL if the quantity is 0.

SQL Stored Procedures

Stored Procedures in SQL

Stored procedures are precompiled database objects that contain one or more SQL statements. They allow you to encapsulate and execute complex sequences of queries, control structures, and logic on the database server.

Syntax

sql
CREATE PROCEDURE procedure_name [parameter1 datatype1 [DEFAULT default_value1], parameter2 datatype2 [DEFAULT default_value2], ...] AS BEGIN -- SQL statements END;
  • procedure_name specifies the name of the stored procedure.
  • parameter1, parameter2, ... (optional) specify the input parameters for the stored procedure.
  • datatype1, datatype2, ... (optional) specify the data types of the input parameters.
  • default_value1, default_value2, ... (optional) specify the default values for the input parameters.
  • SQL statements represent the sequence of SQL statements to be executed.

Example

sql
CREATE PROCEDURE GetCustomerOrders @customer_id INT AS BEGIN SELECT order_id, order_date, total_amount FROM orders WHERE customer_id = @customer_id; END;

In this example, the stored procedure GetCustomerOrders is created with an input parameter @customer_id. It selects the order ID, order date, and total amount from the orders table for the specified customer ID.

SQL Comments

Comments in SQL

Comments are used to add explanatory notes or annotations to SQL code. They are ignored by the database server and have no effect on query execution.

Syntax

sql
-- Single-line comment /* Multi-line comment */
  • Single-line comments start with -- and continue until the end of the line.
  • Multi-line comments start with /* and end with */.

Example

sql
-- This is a single-line comment /* This is a multi-line comment */

In this example, both single-line and multi-line comments are used to add comments to the SQL code. They are helpful for providing context, explanations, or reminders for yourself or other developers.

SQL Operators:

SQL operators are used to perform operations on data within SQL statements. Some common operators include:

  • Arithmetic operators: +, -, *, /, % (modulus)
  • Comparison operators: =, <> or !=, <, >, <=, >=
  • Logical operators: AND, OR, NOT
  • String concatenation: || or CONCAT()
  • NULL-related operators: IS NULL, IS NOT NULL, COALESCE(), NULLIF()

Here's an example that combines different operators in a SQL query:

sql
SELECT name, age, salary FROM employees WHERE age > 30 AND salary >= 5000 ORDER BY name ASC;

These are the details and examples for various SQL topics including syntax, queries, and operators. Remember that specific syntax and functionality may vary depending on the database management system (DBMS) you are using, as SQL implementations can differ slightly.

Post a Comment

0 Comments