MySQL

패턴매칭 (Like / not like ) limit /offset 중복제거 (distinct )

소힌 2022. 1. 27. 16:36

use world;


-- 패턴 매칭이라고 해서 비슷한 것을 찾아내는 것 
select * from country where name Like "%korea"; -- 코리아로 끝나는 국가이름을 가지는 row


-- ~~~ ria로 끝나는 이름을 가진 국가 
select * from country where name like "%ria";

-- region 이 north ~~~ 로 시작하는 국가 alter
select * from country where region like"north%";

-- 이름에 O를 포함하는 국가 
select * from country where name like "%O%";

 select * from country where name like "__O_";
 
 
 -- Region에 america를 포함하지 않는 국가 
 select * from country where region not like "%america%";
 


 

 

 

 

 

 

 select * from country order by population desc;
 
 -- 상위 10개만 보고싶다면 
 select * from country order by population desc
 limit 5;
 
 -- region 값이 asia를 포함하는 국가 중 면적이 가장 좁은 10개의 국가 조회하기 
 
 select * from country where region like "%asia%" order by SurfaceArea limit 10;
 
 select * from country;
 select * from country limit 2 offset 5; -- 건너뛰는 것 
 select * from country limit 5,2;  
 
 
 -- 사용자가 페이지당 10개씩 보여달라고 함 
 -- 사용자가 1페이지를 보여달라고 함 
 
 select * from country limit 10;
 -- 사용자가 2페이지 보여달라고 함 
 select * from country limit 10 offset 10; 
 -- 사용자가 3페이지 보여달라고 함 
 select * from country limit 10 offset 20;