[SQL] SELECT & FROM & DISTINCT & COUNT & LIMIT

less than 1 minute read


SQL Übung

  • SQL 문법 정리(1)
  • SELECTing columns
  • COUNT을 통해 행개수 산출

SELECT & LIMIT

1) SELECTing single column

  • Get the title column from the films table.
SELECT name FROM people;

2) SELECTing multiple column

  • Get the title and release year from the films table
SELECT title, release_year 
FROM films;

2-2) SELECTing multiple column

  • Get all column from the films table
SELECT *
FROM films;

2-3) SELECTing multiple column

  • Get all column from the films table but limit the row as 10
SELECT *
FROM films
LIMIT 10;

# from line 8, 2 rows
SELECT *
FROM films
LIMIT 8, 2;

DISTINCT

3) SELECT DISTINCT

  • Get all the unique countries represented in the films table.
SELECT DISTINCT country 
FROM films;

COUNT

4) COUNT(returns the number of rows in one or more columns)

  • Count the number of rows in the people table.
SELECT COUNT(*)
FROM people;

4-2) COUNT(returns the number of rows in one or more columns)

  • Count the number of (non-missing) birth dates in the people table.
SELECT COUNT(birthdate)
FROM people;

4-3) COUNT(returns the number of rows in one or more columns)

  • Count the number of unique birth dates in the people table.
SELECT COUNT(DISTINCT birthdate)
FROM people;

Tags:

Categories:

Updated: