๊ด€๋ฆฌ ๋ฉ”๋‰ด

ruriruriya

[DB] ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค MySQL - ๋ฐ์ดํ„ฐ ์ •๋ ฌ์„ ์œ„ํ•œ order by ๋ณธ๋ฌธ

๐Ÿ›ข๏ธDB/MySQL

[DB] ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค MySQL - ๋ฐ์ดํ„ฐ ์ •๋ ฌ์„ ์œ„ํ•œ order by

๋ฃจ๋ฆฌ์•ผใ…‘ 2023. 11. 29. 19:08
๋ฐ˜์‘ํ˜•

ORDER BY๋Š” SQL์—์„œ ์‚ฌ์šฉ๋˜๋Š” ์ ˆ ์ค‘ ํ•˜๋‚˜๋กœ, ๊ฒฐ๊ณผ๋ฅผ ํŠน์ • ์—ด(column) ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•˜๋Š” ๋ฐ์— ์‚ฌ์šฉ๋œ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ๋ฅผ ์›ํ•˜๋Š” ์ˆœ์„œ๋กœ ์ •๋ ฌํ•˜์—ฌ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋‹ค.

์‚ฌ์šฉํ•  ํ…Œ์ด๋ธ”(books)

 

order by ํ‚ค์›Œ๋“œ

์˜ค๋ฆ„์ฐจ์ˆœ / ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

(โ˜…์ค‘์š”โ˜…)ํ•ญ์ƒ from ์•„๋ž˜์— ์œ„์น˜ํ•ด์•ผ ํ•œ๋‹ค.

author_lname์œผ๋กœ ์ •๋ ฌํ•˜์‹œ์˜ค.

select *
from books
order by author_lname;

 

 

author_lname ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ

select *
from books
order by author_lname asc;

 

author_lname ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ

select *
from books
order by author_lname  desc;

[DB] ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค MySQL - ๋ฐ์ดํ„ฐ ์ •๋ ฌ์„ ์œ„ํ•œ order by

๋ฐ˜์‘ํ˜•