SQL is used to query and extract information from a database. So in this blog post, you will learn about the standard SQL commands that often used to query a database.
Let’s say you have a collection of data stored in the following data table:
CUSTOMER |
|||
customer_id | last_name | first_name | age |
1000 | Bowell | Jason | 43 |
1001 | Gray | Michael | 23 |
1002 | Long | Mary | 30 |
1003 | Jones | Erica | 31 |
- SELECT is used to retrieve selected information that match the criteria specified.
SELECT column1, column2, ….. columnN
FROM table_name
Using the example from the table above (CUSTOMER):
SELECT customer_id, last_name, first_name, age
FROM CUSTOMER;
- If need to select all the columns available in the table then just use *.
SELECT * FROM table_name;
Using the example from the table above (CUSTOMER):
SELECT * FROM CUSTOMER;
- A clause known as “WHERE” can be used to extract specific row observations from the table. You can also specify a condition using comparison operators such as the following:
= (equal) != OR <> (not equal) > (greater than) < (less than) >= (greater than or equal) <= (less than or equal) and so on.
Using the example from the table above (CUSTOMER):
SELECT * FROM CUSTOMER
WHERE age > 35;
OR
SELECT * FROM CUSTOMER
WHERE last_name = “Long”;
Single quotes (“text“) must be used for characters or strings.
Categories: SQL Learning
Leave a Reply