(MySQL)concat/alias/distinct/limit

지며리·2023년 1월 3일
0
post-thumbnail

concat

  • 문자열을 연결하여 호출한다.
select concat('concat',' ', 'test');

concat test


select concat(string1, column) from celeb;

string1과 column의 value들을 연결해서 조회


alias_별칭

select columm (as) column_alias from table_name (as) table_alias;
  • 데이터 조회시 컬럼명과 테이블명을 다른 이름으로 지정한다.

select concat(s.season,'-',s.episode, '(',s.broadcast_date,')') '방송정보', 
		concat(c.name, '(', c.job_title,')') '출연자정보'
        from celeb c, snl_show s 
        where name = host;


DISTINCT

  • 검색한 결과의 중복 제거
select distinct column1, column2, ... 
from table_name
where condition;

select agency from celeb;


select distinct agency from celeb;


limit

  • 검색 결과를 정렬된 순으로 주어진 숫자만큼만 조회
select column1, column2...
from table_name
where condition
order by column
limit number;

select * from celeb where sex = 'M' order by age DESC limit 2;

celeb 테이블에서 남자 연예인 중 나이가 가장 많은 2명 조회

profile
호지자불여락지자

0개의 댓글