0% found this document useful (0 votes)
37 views6 pages

Select Query: Select Column List From Tablename Where Conditions

The document discusses the SELECT statement in SQL. It explains that the SELECT statement is used to fetch and retrieve data from MySQL database tables. It provides the basic syntax for a SELECT statement which includes specifying columns, the table name, and optional WHERE conditions. Examples are given showing how to select all columns or specific columns, with and without WHERE conditions. Logical operators that can be used in the WHERE clause like AND, OR, and NOT are also described. Finally, wildcard characters used in the LIKE operator that can match multiple or single characters are explained.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views6 pages

Select Query: Select Column List From Tablename Where Conditions

The document discusses the SELECT statement in SQL. It explains that the SELECT statement is used to fetch and retrieve data from MySQL database tables. It provides the basic syntax for a SELECT statement which includes specifying columns, the table name, and optional WHERE conditions. Examples are given showing how to select all columns or specific columns, with and without WHERE conditions. Logical operators that can be used in the WHERE clause like AND, OR, and NOT are also described. Finally, wildcard characters used in the LIKE operator that can match multiple or single characters are explained.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

SELECT QUERY

- is used to fetch data from the MySQL database.

- is an incredibly powerful tool that enables you to transform data into


information.

- is used to retrieve records from one or more tables in MySQL.

The syntax for the SELECT statement is:

SELECT column list

FROM tableName

WHERE conditions;

• The SELECT statement allows you to get particular columns of


information in the output of the query

• FROM selects the table(s) that the query is going to use to produce the
resulting information

• WHERE is a TRUE/FALSE resulting clause

Fig 1.1
SELECT ALL without WHERE condition.

Using the syntax SELECT * FROM [TableName]; will display all the values
inserted inside the said table.

1|Page
Fig 1.2
SELECT Specific Column without WHERE condition.

Using the syntax SELECT [ColumnName,ColumnName] FROM


[TableName]; will display the values of the columns listed on the select
query.

Fig 1.3
SELECT All Column with WHERE condition.

Using the syntax SELECT *FROM [TableName] WHERE [condition]; will


display the values of the rows that results TRUE to the WHERE Condition of
the statement.

The WHERE clause is used to filter records. It is used to extract only those
records that fulfill a specified condition.

2|Page
The following operators can be used in the WHERE clause:

SYMBOL Meaning

= Equal to

< Less than

<= Less than or equal to

> Greater than

>= Greater than or equal to

<> Or != Not equal to

The WHERE clause can also be combined with AND, OR, and NOT operators.

The AND and OR operators are used to filter records based on more than
one condition:

 The AND operator displays a record if all the conditions separated by


AND is TRUE.

Fig 2.1
SELECT All Column with WHERE condition Combined
with AND logical Operator.

3|Page
Fig 2.2
SELECT All Column with WHERE condition Combined
with AND logical Operator.

Both Figure 2.1 and Figure 2.2 show a SELECT ALL statement with WHERE
clause combined with And Logical Operator the only difference is in Figure
2.1 both conditions in WHERE clause returns TRUE that’s why it displays an
output of 1 row while in Figure 2.2 the condition returns only one true
answer.

 The OR operator displays a record if any of the conditions separated by


OR is TRUE.

Fig 2.3
SELECT All Column with WHERE condition Combined
with OR logical Operator.

4|Page
 The NOT operator displays a record if the condition(s) is NOT TRUE.

Fig 2.4
SELECT All Column with WHERE condition Combined
with NOT logical Operator.

SQL Wildcard Characters

A wildcard character is used to substitute any other character(s) in a string.

Wildcard characters are used with 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 represents zero, one, or multiple characters

5|Page
 _ - The underscore represents a single character

Fig 2.4
SELECT All Column with WHERE condition Combined
with LIKE Special Operator.

The query states that it should display or view all details in the table which has
Name that starts with any character and ends with ‘ead’.

6|Page

You might also like