Sql Where

You add Where clause to the Sql Select to filter the result.

Sql Where syntax:

SELECT column_list
FROM   Table_name(s)
WHERE  conditions 

Let's use the previous CONTACTS table for illustration. You want to get a list of people that live in NSW. (By the way, NSW is a State name in Australia where I used to live).

To do this write this sql:

SELECT surname,
FROM   contacts
WHERE  state = 'NSW' 

This is the result:

White Alan
Johnson Benjamin
Brown Peter

Assume, for the sake of argument, that you know the Id of a person is 4 but you can't remember the name. How do you retrieve the data?

Write the following Sql Where:

SELECT surname,
FROM   contacts
WHERE  cpid = 4 

And the result is:

Anderson Thomas

Recaps. What you need to know about sql where are:

  • Enclosed with quotes if the field in where condition is a text field (check with your system, sometimes it allows either single or double quote).
  • If you use numeric field in the condition, use the value only. No quotes around.

The equality operators that are allowed for the conditions are: = , > , < , >= , <= or <> (unequal).

What if you use the > (greater than) or <(less than) operator in the condition where the field type is a text. How the system compare them?

The answer is using ASCII table. The ASCII table is the numerical representation of characters. (See this link for you reference)

There are three other possible operators that can be used in the Where condition:

  • BETWEEN. This is to get data between certain range. See the Sql Between for more info.
  • LIKE. This is a string operator by using pattern matching. See the Sql Like for more info.
  • IN. This can be used as string or numeric comparison. See the Sql In for more info.

In the next section, we are going to discuss the Sql Distinct to get unique values of a certain column.

Quick link. From here, you can learn the following:

Sql Select
The core of Sql, selecting data from table.

Sql Distinct
Eliminating duplicate values in the output.

Sql Like
Pattern searching for conditions in Where or Having clause

Sql Between
Added to conditions to show results between two values.

Sql In
It enables us to specify multiple values, either as a list or a subquery.

Sql And Or
Connecting two or more conditions in the Where or Having clause.

Sql Count
Counting number of rows.

Sql Sum
Getting the sum of a field

Sql Max
This function will return the highest value.

Sql Min
This function will return the lowest value.

Sql Avg
This function will return the average value.

Sql Order By
Sorting the output

Sql Group By
Grouping rows into sets.

Sql Having
To filter the result of aggregation

Perseverance: Cliffhanger
Buy at AllPosters.com
What the mind can conceive and believe, it can achieve.

Positive Resources

All of us have at least two or three things that excite us. We could talk about these subjects for hours. Good news!. Did you know that Site Built It! can turn this type of deep interest and enthusiasm into a revenue-generating business?

Review some of the Site Build It! case studies and you'll absolutely discover something that ignites more positive ideas into your mind.

SBI! Video Tour

Invest the most
important 30 minutes
you will spend online.

Click, sit back, and
understand why SBI!
makes you succeed.