「SQL」 distinct文で指定項目の重複行を非表示にする

2021年8月22日

書式
select distinct 項目名 from テーブル名
select distinct 項目名1,項目名2,xxx from テーブル名

使用例1

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
select distinct
FirstName
from
employees
where
FirstName = "Nancy";
select distinct FirstName from employees where FirstName = "Nancy";
select distinct
    FirstName 
from
    employees 
where
    FirstName = "Nancy";

結果

FirstName
Nancy

使用例2

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
select distinct
employeeid
, firstname
, birthdate
from
employees
where
FirstName = "Nancy";
select distinct employeeid , firstname , birthdate from employees where FirstName = "Nancy";
select distinct
    employeeid
    , firstname
    , birthdate 
from
    employees 
where
    FirstName = "Nancy";

結果

EmployeeID FirstName BirthDate
1 Nancy 1968-12-08

SQL

Posted by arkgame