Ingxelo ekhethiweyo ye-SQL

I SELECT Ingxelo kwi-SQL isetyenziselwa ukufumana idatha kwitafile yedatha.

Singasebenzisa SELECT ingxelo yokufumana idatha kwiikholamu ezichaziweyo okanye kuzo zonke iikholamu.



SQL KHETHA syntax

I SELECT ingxelo ine-syntax elandelayo:


SELECT column1, column2, ... FROM table_name;

Imizekelo yeNkcazo ye-SQL

Masithi sinetafile ebizwa ngokuba 'ngabasebenzi' enedatha elandelayo:

+------------+-----------+----------+------------+ | EmployeeID | FirstName | LastName | Department | +------------+-----------+----------+------------+ | 1

| Mark
| Otto
| Finance | | 2

| Jacob
| Thornton | IT
| | 3

| Su
| Bird
| Marketing | | 4

| Sam
| Burger | IT
| +------------+-----------+----------+------------+


KHETHA ukusuka kwikholamu

Ukukhetha ikholamu 'yeSebe' kwitafile 'Abasebenzi':


SELECT Department FROM Employees;

Iziphumo:

+------------+ | Department | +------------+ | Finance | | IT
| | Marketing | | IT
| +------------+


KHETHA Kwiikholamu ezininzi

Ukukhetha iikholam “zeSebe” nele- “EmployeeID” kwiitheyibhile “zabasebenzi”:

SELECT EmployeeID, Department FROM Employees;

Iziphumo:

+------------+------------+ | EmployeeID | Department | +------------+------------+ | 1

| Finance | | 2

| IT
| | 3

| Marketing | | 4

| IT
| +------------+------------+


KHETHA * Ingxelo

Ukukhetha zonke iikholamu kwitafile 'Abasebenzi':


SELECT * FROM Employees;

Iziphumo:

+------------+-----------+----------+------------+ | EmployeeID | FirstName | LastName | Department | +------------+-----------+----------+------------+ | 1

| Mark
| Otto
| Finance | | 2

| Jacob
| Thornton | IT
| | 3

| Su
| Bird
| Marketing | | 4

| Sam
| Burger | IT
| +------------+-----------+----------+------------+


Iziphumo zokucoca usebenzisa APHO iGatya

Singazicoca iziphumo kwi | _ _ + _ | umbuzo ngokusebenzisa SELECT Igatya.

Umzekelo, ukukhetha bonke abasebenzi kwi 'IT Department' sebenzisa:

WHERE

Iziphumo:


SELECT * FROM Employees WHERE Department='IT'

Ngokunjalo, ukukhetha zonke ii-Id zomqeshwa ezikwi 'IT Department' sisebenzisa:

+------------+-----------+----------+------------+ | EmployeeID | FirstName | LastName | Department | +------------+-----------+----------+------------+ | 2

| Jacob
| Thornton | IT
| | 4

| Sam
| Burger | IT
| +------------+-----------+----------+------------+

Iziphumo:

SELECT EmployeeID FROM Employees WHERE Department='IT'