SQL – Basic Commands – SELECT & Comparison Operators

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
  1. 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;

  1. 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;

  1. 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.

Advertisements


Categories: SQL Learning

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: