Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre SQL Where | Database & Introduction to Syntax
SQL Tutorial for Beginners
course content

Contenu du cours

SQL Tutorial for Beginners

SQL Tutorial for Beginners

1. Database & Introduction to Syntax
2. SQL Aggregate Functions
3. Filtering Statements

book
SQL Where

You’ll need to filter your selected data very often, so you need to use WHERE keyword. After WHERE you put some condition or combination of them. Usually it is some column's values limitations.

For example, you want to select records where singer is AC/DC:

12
SELECT * FROM songs WHERE singer = 'AC/DC'
copy

Another example of the query using the WHERE statement. It retrieves all records with a price column value greater than 100. The syntax is pretty easy to understand: WHERE price > 100.

12
SELECT * FROM songs WHERE price > 100
copy

Here you can see the main syntax.

  • Use = to find fields which values are equal to some naming.
  • Use != or <> to find non-equal fields.
  • Use >, <, >=, <= for comparing.
  • Use single quotes 'Quotes' for string values.
  • Use () brackets for prioritization.
123
/* all records where year column is greater or equal than 1970*/ SELECT * FROM songs WHERE year >= 1970
copy

For string values, you have to write them inside single quotes. Like 'ABBA', 'Toxic' etc. Check carefully string values in the condition statements: no extra spaces, correct capitalization (for example, Britney Spears is correct, not BRITNEY SPEARS or britney spears). Otherwise, you'll receive the Internal Server Error.

Tâche

Swipe to start coding

Select all records with Britney Spears as a singer. Change your query to select only Britney Spears songs' titles (not full records, only column title).

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 5
toggle bottom row

book
SQL Where

You’ll need to filter your selected data very often, so you need to use WHERE keyword. After WHERE you put some condition or combination of them. Usually it is some column's values limitations.

For example, you want to select records where singer is AC/DC:

12
SELECT * FROM songs WHERE singer = 'AC/DC'
copy

Another example of the query using the WHERE statement. It retrieves all records with a price column value greater than 100. The syntax is pretty easy to understand: WHERE price > 100.

12
SELECT * FROM songs WHERE price > 100
copy

Here you can see the main syntax.

  • Use = to find fields which values are equal to some naming.
  • Use != or <> to find non-equal fields.
  • Use >, <, >=, <= for comparing.
  • Use single quotes 'Quotes' for string values.
  • Use () brackets for prioritization.
123
/* all records where year column is greater or equal than 1970*/ SELECT * FROM songs WHERE year >= 1970
copy

For string values, you have to write them inside single quotes. Like 'ABBA', 'Toxic' etc. Check carefully string values in the condition statements: no extra spaces, correct capitalization (for example, Britney Spears is correct, not BRITNEY SPEARS or britney spears). Otherwise, you'll receive the Internal Server Error.

Tâche

Swipe to start coding

Select all records with Britney Spears as a singer. Change your query to select only Britney Spears songs' titles (not full records, only column title).

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 5
Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Nous sommes désolés de vous informer que quelque chose s'est mal passé. Qu'est-il arrivé ?
some-alt