AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

SQL where


<< Previous Page
SQL tutorial
Next Page >>
SQL tutorial

SQL Tutorial » SQL where

SQL "WHERE" (without quotes) clause is used to filter rows and to extract only those records from SQL database that fulfill a specified condition.
Also WHERE is used in the UPDATE, DELETE statement, etc.,

Syntax:

SELECT column1, column2, ... columnN
FROM table_name
WHERE condition;
Note: If you omit WHERE clause, all records will be deleted! if this is used to delete an row in database.

Let's look at the "Users" table: We will have six columns as: "id", "first_name", "country", "user_name", "email" and "reg_date":

ID First Name Last Name Country Email
1 Clark Kent USA clarkkent@mail.com
2 Pire Joveau France pierej@mail.com
3 Nicky Anderson USA nickya@mail.com
4 Pepe Martínez Spain martinezpeper@mail.com
5 Peter Parker SUA peterparker@mail.com

 

SQL where

In the next examples we display people from USA from "Users" table using WHERE clause:

SELECT * FROM Users
WHERE Country='USA';

Output displayed:

ID First Name Last Name Country Email
1 Clark Kent USA clarkkent@mail.com
3 Nicky Anderson USA nickya@mail.com
5 Peter Parker SUA peterparker@mail.com

Related subjects:
How to create database phpmyadmin? Insert multiple rows PHP select / view data Conect to MySQLi PHP MySQLi create table

Tags: sql where, multiple conditions, where clause, where date, where in list, not in, where not null, between,update sql, What is the use of where in SQL?, What is == in SQL?, What are the SQL clauses?

 

WHERE clause with Text Fields vs. Numeric Fields

As we saw in the previous example SQL requires single quotes around text values, but also allow double quotes most database systems.
In the next example, numeric fields should not be enclosed in quotes:

SELECT * FROM Users
WHERE ID=4;

Output displayed:

ID First Name Last Name Country Email
4 Pepe Martínez Spain martinezpeper@mail.com

 

WHERE Clause Operators In the SQL

WHERE Clause Operators In the SQL - WHERE clause the following operators can be used:

  1. = Equal
  2. < Less than
  3. > Greater than
  4. <= Less than or equal
  5. >= Greater than or equal
  6. <> Not equal. Operator may be written as !=
  7. LIKE Search for a pattern
  8. BETWEEN Between a certain range
  9. IN Specify multiple possible values for a column

 



sql where, multiple conditions, where clause, where date, where in list, not in, where not null, between,update sql, What is the use of where in SQL?, What is == in SQL?, What are the SQL clauses?
SQL where clause - sql tutorial

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Home - Database
SQL - Database
SQL Syntax
SQL Select Data
SQL Insert Data
SQL Update
SQL Delete Row
PHP mysqli_query()
SQL order
SQL Create Database
SQL Display Data
SQL Count()
SQL mysqli_connect
SQL create table
SQL Where And & Or
SQL like Syntax
SQL Between Operator
SQL IN Operator
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Error: Unable to connect to MySQL. Debugging errno: 1045 Debugging error: Access denied for user 'u142985959_ager'@'localhost' (using password: YES)