In this lesson, we will talk about Where Condition, which is one of the most used operators and commands in SQL server.
Where requirement is basically used to filter according to the criteria we give in a data set.
This is a command we use when adding, deleting, not just pulling data.
For example, when I say SELECT * FROM people, I will draw the contacts table. If I want to shoot the ones in Ankara, I will use a code like this.
SELECT * FROM contacts
WHERE il = 'Ankara'

Or I might want to attract those with a date of birth greater than 1990. In this we will use the following block of code.

SELECT * FROM contacts
WHERE birth date> '1990-01-01'

Or I might want to attract girls with a gender in my painting. In this we will use the following codes.

SELECT * FROM contacts
WHERE Gender = 'K'

Actually, I have done filtering here. These where conditions have multiple usage parameters. It may be equal, there may be those named Ayşe, Ahmet. Let's show them now.

=:     Equal (WHERE City = 'Ankara') Here we brought people whose province is Ankara.

<>:   Not Equal  (WHERE City <> 'Ankara') Here we brought people whose province is outside Ankara)

<:   Less than ( WHERE date of birth <'1990-01-01' ) It will bring birth dates of 1990 or earlier.

>:   Greater  ( WHERE date of birth > '1990-01-01' ) It will bring birth dates from 1990 onwards. 
=:   Less than or equal  ( WHERE date of birth <= '1990-01-01'  Returns those born in one of January.
> =:   Greater than or equal to  ( WHERE date of birth> = '1990-01-01' ) Returns those born in one of January. Small equals and Big equals the same. 

Between: Between  (WHERE age BETWEEN 25 AND 40) Brings what is between the two ranges. Here it brings us between the ages of 25 and 40.

Starts with : like , ends with, contains
If I say her name starts with Ali: (WHERE name is LIKE 'ALI%')
If I say the first and last name ends with Özdemir, this time we add the percent sign to the beginning.
(WHERE name LIKE '% ALİ')

If I want to use includes, this time I bring a% sign to both the beginning and the end
(WHERE name LIKE '% ALİ%')

In:   In  (WHERE il IN ('Ankara', 'Bursa')   For example, I have more than one field in my where condition. I want to bring the ones in Ankara, Bursa, the code we will use for this: 

Not Like: Does not start with, end with, does not contain. The opposite of our like command. We write NOT LIKE instead of just LIKE.

Not in: not in. (WHERE il NOT IN ('Ankara', 'Bursa')  For example, if we want to bring all provinces except Ankara and Bursa, we will use the Not in command. 

This is our lesson. In our other lesson, we will show how these commands are applied. Good work to everyone.

Yorum Yap

Daha yeni Daha eski