Clauza WHERE

postat acum 4 ani de Stefanescu Mihai in categorie SQL

Clauza WHERE este folosita pentru a specifica o anumita conditie la selectarea datelor dintr-un tabel sau mai multe.

Daca este satisfacuta conditia data in clauza WHERE atunci sunt afisate rezultatele respective din tabel.

Aceasta clauza WHERE nu poate fi folosita doar in SELECT ci si in UPDATE, DETELE, etc pe care le vom discuta in articolele ce urmeaza.Sintaxa de baza a clauzei WHERE

SELECT Coloana1, Coloana2, ColoanaN 
FROM numeTabel
WHERE [conditie]

Consideram ca avem urmatorul tabel cu angajati:

+----+----------+--------+--------------+-----------+
| ID | NUME     | VARSTA | ADRESA       | SALARIU   |
+----+----------+--------+--------------+-----------+
|  1 | Mihai    |    22  | Bucuresti    | 10000.00  |
|  2 | Alex     |    25  | Pitesti      |  1500.00  |
|  3 | George   |    23  | Cluj         |  2000.00  |
|  4 | Mircea   |    25  | Iasi         |  6500.00  |
+----+----------+--------+--------------+-----------+

Mai jos am scris o interogare ce va selecta decat angajati ce au un salariu mai mare de 2000:

SQL> SELECT ID, Nume, Salariu 
FROM angajati
WHERE Salariu > 2000;

Va fi afisat urmatorul rezultat:

+----+----------+-----------+
| ID | NUME     |  SALARIU  |
+----+----------+-----------+
|  1 | Mihai    | 10000.00  |
|  4 | Mircea   |  6500.00  |
+----+----------+-----------+

Mai jos am scris o interogare ce va selecta o singura inregistrare din tabel, si anume inregistrarea care are o anumita valoare in campul Nume.

SQL> SELECT ID, Nume, Salariu 
FROM angajati
WHERE Nume = 'Mihai';

Aceasta interogare va avea urmatorul rezultat:

+----+----------+-----------+
| ID | NUME     |  SALARIU  |
+----+----------+-----------+
|  1 | Mihai    | 10000.00  |
+----+----------+-----------+

 

Sunt un tanar programator din Bucuresti ce lucreaza in PHP/Mysql (MySqli/PDO), Laravel, CodeIgniter, MySQL, PostgreSQL, Wordpress, HTML5/CSS3, Sass, Photoshop si multe altele.
Google+ Community Facebook Group
Acest articol a fost mutat de pe vechea platforma.
Pentru orice eroare aparuta la mutare va rog sa ma contactati!

Comentariu postate de dani
Mersi frumos de informatii. Apreciez ca sunt bine structurate si utile.
Comentariu postate de free minecraft download la data de 14.05.2019
I'm curious to find out what blog platform you're utilizing? I'm experiencing some minor security problems with my latest blog and I would like to find something more safe. Do you have any solutions?
Comentariu postate de download minecraft la data de 15.05.2019
Greate pieces. Keep posting such kind of info on your site. Im really impressed by your site. Hello there, You've performed an excellent job. I will certainly digg it and for my part suggest to my friends. I'm confident they'll be benefited from this site.
Comentariu postate de download minecraft for free la data de 17.05.2019
Simply wish to say your article is as astonishing. The clarity to your post is simply excellent and that i could assume you are a professional on this subject. Well along with your permission let me to take hold of your feed to keep updated with approaching post. Thanks one million and please carry on the gratifying work.