The SELECT statement is used to look for data, or to consult our tables.
The syntax for SELECT statement is:
Example 1
Tip: The asterisk (*) is a quick way of selecting all columns!
Or you can restrict the search by calling the rows you chose
Example 2
SELECT using condition/s
Sintax:
Tip: The (--) is a quick way of commenting a line !
Example:
Also is important to mention that when the values that will be used in the conditions a string we must place it in single quotes.
Integer values do not require single quotes.
Example:
Conditional selections used in the where clause:
= Equal
It will bring all the names that have the id equal to 1.
Greater than
It will bring all the names that have the id bigger then 1.
< Less than
It will bring all the names that have the id smaller then 2.
= Greater than or equal
<= Less than or equal
< Not equal to
LIKE
The LIKE pattern matching operator can also be used in the conditional selection of the where clause. Like is a very powerful operator that allows you to select only rows that are "like" what you specify. The percent sign "%" can be used as a wild card to match any possible character that might appear before or after the characters specified.
Notice that the select returned all the names that end up in 'ke' , knowing that '%' sign replaced the rest of the string.
We can use the '%' wildcard as well at the end :
Example:
At the beginning and at the end.
Example:
See that the select returned all the names that have letter 'i' inside.
Remember that we can use more then one character between the wildcard operators.
Example:
We will learn more about the power of select after we go thrum the basics of Sql first.