The SQL BETWEEN Operator

The SQL BETWEEN Operator

The SQL BETWEEN Operator The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates. The BETWEEN operator is inclusive: begin and end values are included. BETWEEN Syntax SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2; BETWEEN Example The following SQL statement selects all products with a price BETWEEN 10 and 20: Example SELECT * FROM Products […]

The SQL IN Operator

The SQL IN Operator

The SQL IN Operator The IN operator allows you to specify multiple values in a WHERE clause. The IN operator is a shorthand for multiple OR conditions. IN Syntax SELECT column_name(s) FROM table_name WHERE column_name IN (value1, value2, …); SELECT column_name(s) FROM table_name WHERE column_name IN (SELECT STATEMENT); IN Operator Examples The following SQL statement selects all customers that are located in “Germany”, “France” and “UK”: Example […]

The SQL LIKE Operator

The SQL LIKE Operator

The SQL LIKE Operator The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards used in conjunction with the LIKE operator: The percent sign and the underscore can also be used in combinations! LIKE Syntax SELECT column1, column2, … FROM table_name WHERE columnN LIKE pattern; Tip: You can also […]

The SQL COUNT(), AVG() and SUM() Functions

The SQL COUNT(), AVG() and SUM() Functions

The SQL COUNT(), AVG() and SUM() Functions The COUNT() function returns the number of rows that matches a specified criteria. The AVG() function returns the average value of a numeric column. The SUM() function returns the total sum of a numeric column. COUNT() Syntax SELECT COUNT(column_name) FROM table_name WHERE condition; AVG() Syntax SELECT AVG(column_name) FROM table_name WHERE condition; SUM() Syntax SELECT SUM(column_name) […]

The SQL MIN() and MAX() Functions

The SQL MIN() and MAX() Functions

The SQL MIN() and MAX() Functions The MIN() function returns the smallest value of the selected column. The MAX() function returns the largest value of the selected column. MIN() Syntax SELECT MIN(column_name) FROM table_name WHERE condition; MAX() Syntax SELECT MAX(column_name) FROM table_name WHERE condition; Demo Database Below is a selection from the “Products” table in the Northwind sample database: ProductID ProductName […]

The SQL UPDATE Statement

The SQL UPDATE Statement The UPDATE statement is used to modify the existing records in a table. UPDATE Syntax UPDATE table_name SET column1 = value1, column2 = value2, … WHERE condition; UPDATE Table The following SQL statement updates the first customer (CustomerID = 1) with a new contact person and a new city. Example UPDATE Customers SET ContactName = ‘Alfred Schmidt’, City= ‘Frankfurt’ WHERE CustomerID = 1; UPDATE Multiple Records It […]

The SQL DELETE Statement

The SQL DELETE Statement The DELETE statement is used to delete existing records in a table. DELETE Syntax DELETE FROM table_name WHERE condition; SQL DELETE Example The following SQL statement deletes the customer “Alfreds Futterkiste” from the “Customers” table: Example DELETE FROM Customers WHERE CustomerName=’Alfreds Futterkiste’ The “Customers” table will now look like this: CustomerID CustomerName ContactName Address City PostalCode Country 2 Ana […]

Enjoy this blog? Please spread the word :)