์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- https://m.blog.naver.com/tt2t2am1118/221010125300
- ํผํ
- JS #ํ๋ก์ ํธ
- callback
- execCommand
- await
- mysql
- addEventListener
- webpack
- Import
- eport
- slow and steady
- prj
- sql
- object
- setTimeout()
- ๊ฒ์
- js
- Porject
- ajax
- db
- ๋๊ธฐ
- json
- async
- Project
- promise
- database
- https://youtube.com/playlist?list=PLuHgQVnccGMA5836CvWfieEQy0T0ov6Jh&si=FTaYv8m21EhO-A2K
- ๋น๋๊ธฐ
- ์ฐธ๊ณ ๋ธ๋ก๊ทธ
- Today
- Total
C-log
๐๏ธ๋์ SQL : SELECT ๋ณธ๋ฌธ
MySQL์์ SELECT๋ ๊ต์ฅํ ๋ง์ด ์ฌ์ฉ๋๋ ๋ช ๋ น์ด ์ค ํ๋์ด๋ค. ์์ ๋ฐฐ์ด ์ ๋ ฅํ ์ ์ฒด ๋ฐ์ดํฐ๊ฐ์ ๋ณผ ์ ์๋ ๊ฒ ์ธ์๋ ๋ด๊ฐ ํ์ํ ๊ฐ๋ง ๋ณผ ์ ์๊ฒ ์ ํํ ์ ์๋ ๋ช ๋ น์ด ๋ฐฉ์์ ๋ฐฐ์ ๋ณผ ๊ฒ์ด๋ค. ์๋ ์ฝ๋๋ฅผ ์ดํด๋ณด์.
SELECT id,created,author FROM topic;
MariaDB [opentutorials]> SELECT id,created,author FROM topic;
+----+---------------------+--------+
| id | created | author |
+----+---------------------+--------+
| 1 | 2023-09-10 15:36:30 | egoing |
| 2 | 2023-09-10 15:51:16 | egoing |
| 3 | 2023-09-10 15:57:25 | duru |
| 4 | 2023-09-10 15:58:31 | taeho |
| 5 | 2023-09-10 15:59:20 | egoing |
+----+---------------------+--------+
5 rows in set (0.001 sec)
์์์ ๋ณด์๋ฏ์ด ์ ํํ colum๋ค๋ง ์ ํํด์ ๋ณผ ์ ์๋ค. ํ์ง๋ง ์ฐ๋ฆฌ๋ ๋ค์ ์๊ฐํด ๋ณผ ์ ์๋ค. author์์ ์ค๋ก์ง egoing๋ง ํด๋น๋๋ colum์ ์ ํํด์ ๋ณด๊ณ ์ถ์ ์ ์๋ค. ๊ทธ๋ ๊ธฐ ์ํด์๋ WHERE๋ฌธ์ ์ฌ์ฉํด์ผํ๋ค. ์๋ ์ฝ๋๋ฅผ ์ดํด๋ณด์.
SELECT id,title,created,author FROM topic WHERE author='egoing';
MariaDB [opentutorials]> SELECT id,title,created,author FROM topic WHERE author='egoing';
+----+---------+---------------------+--------+
| id | title | created | author |
+----+---------+---------------------+--------+
| 1 | MySQL | 2023-09-10 15:36:30 | egoing |
| 2 | ORACLE | 2023-09-10 15:51:16 | egoing |
| 5 | MongoDB | 2023-09-10 15:59:20 | egoing |
+----+---------+---------------------+--------+
3 rows in set (0.001 sec)
์์์ ๋ณด์๋ฏ์ด WHERE๋ฌธ์ ์ฌ์ฉํด์ ํด๋น colum์ผ๋ก ์ธ๋ถ์ ์ธ ๋ด์ฉ์ ์ ํํ๋ค. ๊ฒฐ๊ณผ์ ์ผ๋ก ์ฐ๋ฆฌ๊ฐ ๋ณด๊ณ ์ถ์ ๋ฐ์ดํฐ๋ค๋ง ์ ํ ๋์ด์ ์คํค๋ง๋ฅผ ๋ณผ ์ ์๋ค. ๋ ๋์๊ฐ์ ํด๋น ๋ฐ์ดํฐ์ ๊ฐ์ ๋ด๋ฆผ์ฐจ์์ผ๋ก ๋ณด๊ธฐ์ํด์ ์๋ ์ฝ๋๋ก ์ฌ์ฉํ๋ฉด ๋๋ค.
SELECT id,title,created,author FROM topic WHERE author='egoing' ORDER BY id DESC;
MariaDB [opentutorials]> SELECT id,title,created,author FROM topic
WHERE author='egoing' ORDER BY id DESC;
+----+---------+---------------------+--------+
| id | title | created | author |
+----+---------+---------------------+--------+
| 5 | MongoDB | 2023-09-10 15:59:20 | egoing |
| 2 | ORACLE | 2023-09-10 15:51:16 | egoing |
| 1 | MySQL | 2023-09-10 15:36:30 | egoing |
+----+---------+---------------------+--------+
3 rows in set (0.001 sec)
์ฌ๊ธฐ์ ์ฐ๋ฆฌ๊ฐ ํ์ธํด๋ณผ ํ์๊ฐ ์๋ ๊ฒ์ ์์ ์ฌ์ฉํ๋ DESC๋ Descirption์ด๋ผ๋ ์ค๋ช ์ ์๋ฏธํ์ง๋ฉด ์ฌ๊ธฐ์ DESC๋ Descending์ด๋ผ๋ ๋ด๋ฆผ์ฐจ์์ ์๋ฏธํ๋ค. ๋ฐ๋๋ก ์ค๋ฆ์ฐจ์์ ์๋ฏธํ๋ ASC์ธ Ascending๋ ์๋์ ๊ฐ๋ค.
SELECT id,title,created,author FROM topic WHERE author='egoing' ORDER BY id ASC;
MariaDB [opentutorials]> SELECT id,title,created,author FROM topic
WHERE author='egoing' ORDER BY id ASC;
+----+---------+---------------------+--------+
| id | title | created | author |
+----+---------+---------------------+--------+
| 1 | MySQL | 2023-09-10 15:36:30 | egoing |
| 2 | ORACLE | 2023-09-10 15:51:16 | egoing |
| 5 | MongoDB | 2023-09-10 15:59:20 | egoing |
+----+---------+---------------------+--------+
3 rows in set (0.001 sec)
์ดํ ๋ชจ๋ ๋ฐ์ดํฐ๋ง ๋ณด์ง ์๊ณ ๋ด๊ฐ ์ํ๋ ๋งํผ์ ๋ฐ์ดํฐ๋ง ๋ณด๊ณ ์ถ๋ค๋ฉด ์๋์ ๊ฐ์ด LIMIT์ด๋ผ๋ ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ๋ฉด ๋๋ค.
SELECT id,title,created,author FROM topic WHERE author='egoing' ORDER BY id DESC LIMIT 2;
MariaDB [opentutorials]> SELECT id,title,created,author FROM topic
WHERE author='egoing' ORDER BY id DESC LIMIT 2;
+----+---------+---------------------+--------+
| id | title | created | author |
+----+---------+---------------------+--------+
| 5 | MongoDB | 2023-09-10 15:59:20 | egoing |
| 2 | ORACLE | 2023-09-10 15:51:16 | egoing |
+----+---------+---------------------+--------+
2 rows in set (0.000 sec)
์ด๋ ๊ฒ ์ฐ๋ฆฌ๋ ๋ฐ์ดํฐ๋ฅผ ์ ํ์ ์ผ๋ก ๋ณผ ์ ์๋ ๋ช ๋ น์ด๋ค์ ์ดํด ๋ณด์๋ค.
'DB > ๐ฌMySQL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐๏ธ๋์ SQL : DELETE (0) | 2023.09.11 |
---|---|
๐๏ธ๋์ SQL : UPDATE (0) | 2023.09.11 |
๐๏ธ๋์ SQL : ๋ณต์ต์ ํ์! (0) | 2023.09.10 |
๐๏ธ๋์ SQL : INSERT (0) | 2023.09.10 |
๐๏ธ๋์ SQL : TABLE ์์ฑํ๊ธฐ ๊ทธ๋ฆฌ๊ณ Workbech (0) | 2023.09.09 |