node.js - 2
2019.10.08 08:47
Node.js MySQL Order By
조회 수 285 추천 수 0 댓글 0
결과 정렬
var mysql = require('mysql'); var con = mysql.createConnection({ host: "localhost", user: "yourusername", password: "yourpassword", database: "mydb" }); con.connect(function(err) { if (err) throw err; con.query("SELECT * FROM customers ORDER BY name", function (err, result) { if (err) throw err; console.log(result); }); });
C:\Users\Your Name>node demo_db_orderby.js
결과는 아래와 같다.
[ { id: 3, name: 'Amy', address: 'Apple st 652'}, { id: 11, name: 'Ben', address: 'Park Lane 38'}, { id: 7, name: 'Betty', address: 'Green Grass 1'}, { id: 13, name: 'Chuck', address: 'Main Road 989'}, { id: 4, name: 'Hannah', address: 'Mountain 21'}, { id: 1, name: 'John', address: 'Higheay 71'}, { id: 5, name: 'Michael', address: 'Valley 345'}, { id: 2, name: 'Peter', address: 'Lowstreet 4'}, { id: 8, name: 'Richard', address: 'Sky st 331'}, { id: 6, name: 'Sandy', address: 'Ocean blvd 2'}, { id: 9, name: 'Susan', address: 'One way 98'}, { id: 10, name: 'Vicky', address: 'Yellow Garden 2'}, { id: 14, name: 'Viola', address: 'Sideway 1633'}, { id: 12, name: 'William', address: 'Central st 954'} ]
ORDER BY DESC
var mysql = require('mysql'); var con = mysql.createConnection({ host: "localhost", user: "yourusername", password: "yourpassword", database: "mydb" }); con.connect(function(err) { if (err) throw err; con.query("SELECT * FROM customers ORDER BY name DESC", function (err, result) { if (err) throw err; console.log(result); }); });
C:\Users\Your Name>node demo_db_orderby_desc.js
[ { id: 12, name: 'William', address: 'Central st 954'}, { id: 14, name: 'Viola', address: 'Sideway 1633'}, { id: 10, name: 'Vicky', address: 'Yellow Garden 2'}, { id: 9, name: 'Susan', address: 'One way 98'}, { id: 6, name: 'Sandy', address: 'Ocean blvd 2'}, { id: 8, name: 'Richard', address: 'Sky st 331'}, { id: 2, name: 'Peter', address: 'Lowstreet 4'}, { id: 5, name: 'Michael', address: 'Valley 345'}, { id: 1, name: 'John', address: 'Higheay 71'}, { id: 4, name: 'Hannah', address: 'Mountain 21'}, { id: 13, name: 'Chuck', address: 'Main Road 989'}, { id: 7, name: 'Betty', address: 'Green Grass 1'}, { id: 11, name: 'Ben', address: 'Park Lane 38'}, { id: 3, name: 'Amy', address: 'Apple st 652'} ]
번호 | 분류 | 제목 | 날짜 | 조회 수 |
---|---|---|---|---|
38 | node.js - 1 | Express에서 POST 방식 사용하기 | 2019.10.16 | 349 |
37 | node.js - 1 | Express에서 MySql 사용 | 2019.10.10 | 843 |
36 | node.js - 2 | Node.js MySQL Limit | 2019.10.10 | 288 |
35 | node.js - 2 | Node.js MySQL Update | 2019.10.10 | 276 |
34 | node.js - 2 | Node.js MySQL Drop Table | 2019.10.08 | 357 |
33 | node.js - 2 | Node.js MySQL Delete | 2019.10.08 | 302 |
» | node.js - 2 | Node.js MySQL Order By | 2019.10.08 | 285 |
31 | node.js - 2 | Node.js MySQL Where | 2019.10.08 | 494 |
30 | node.js - 2 | Node.js MySQL Select From | 2019.10.08 | 630 |
29 | node.js - 2 | Node.js MySQL Insert Into | 2019.10.01 | 933 |
28 | node.js - 2 | Node.js MySQL Create Table | 2019.10.01 | 324 |
27 | PUG | PUG 07 / INCLUDES | 2019.10.01 | 358 |
26 | PUG | PUG 06 / DOCTYPE | 2019.10.01 | 431 |
25 | node.js - 2 | Node.js MySQL | 2019.09.27 | 315 |
24 | node.js - 2 | NPM의 사용 | 2019.09.26 | 313 |
23 | node.js - 2 | Node.js URL Module | 2019.09.26 | 461 |
22 | PUG | PUG 05 / Conditionals | 2019.09.19 | 755 |
21 | PUG | PUG 04 / Comments | 2019.09.19 | 329 |
20 | PUG | PUG 03 / Code | 2019.09.19 | 691 |
19 | PUG | PUG 02 / Case | 2019.09.19 | 367 |