Hämta Flera Kolumner
Inspektera tabellen
Låt oss fördjupa oss i databasen country
. Denna databas innehåller en enda tabell, även den kallad country
. Vi ska titta närmare på datan i denna tabell.
Denna tabell innehåller 15 rader, vilket representerar 15 unika poster för olika länder.
Nu ska vi diskutera kolumnerna. Tabellen innehåller 7 kolumner: id
, name
, continent
, region
, SurfaceArea
, capital
och population
.
-
id
- the unique identifier for each record; -
name
- the name of the country; -
continent
- the continent where the country is located; -
region
- the specific region within the continent; -
SurfaceArea
- the total land area of the country; -
capital
- the capital city of the country; -
population
- the number of people living in the country.
Syntax för att hämta flera kolumner
För att hämta flera kolumner används SELECT
-satsen. Efter SELECT
listar du de kolumnnamn du vill hämta, separerade med kommatecken.
Syntaxen ser ut så här:
SELECT column1, column2, column3
FROM table_name;
Här är ett exempel på hur du väljer tre kolumner från tabellen country
:
SELECT id, name, capital FROM country;
Swipe to start coding
Skriv en SQL-fråga för att hämta kolumnerna continent
och population
från tabellen country
.
Observera
Kom ihåg att kolumner måste separeras med kommatecken!
Lösning
Tack för dina kommentarer!