Introducing MySQL SQL 43 As you can see (J2ee hosting)

Introducing MySQL SQL 43 As you can see in the output from the query, the data is displayed in alphabetical order based on the username. You can also sort based on a numeric column: mysql> SELECT * FROM acc ORDER BY acc_id; +———+———–+———-+—————-+ | acc_id | username | password | ts | +———+———–+———-+—————-+ | 1034033 | jsmith | smithy | 20021014112438 | | 1034034 | jime | NULL | 20021014112415 | | 1034055 | jdoe | doey | 20021014112501 | | 1034067 | jthompson | james2 | 20021014113403 | | 1034089 | sstanford | stanford | 20021014113407 | | 1034123 | blewis | lewis | 20021014112252 | | 1034154 | ysheets | sheets | 20021014113416 | | 1034546 | jjmyers | NULL | 20021014113422 | +———+———–+———-+—————-+ 8 rows in set (0.00 sec) Now the records are ordered based on the acc_id, which is an integer. The ORDER BY clause can also be used with the WHERE clause. For example: mysql> SELECT * FROM acc WHERE ts < now() ORDER BY ts; +---------+-----------+----------+----------------+ | acc_id | username | password | ts | +---------+-----------+----------+----------------+ | 1034123 | blewis | lewis | 20021014112252 | | 1034034 | jime | NULL | 20021014112415 | | 1034033 | jsmith | smithy | 20021014112438 | | 1034055 | jdoe | doey | 20021014112501 | | 1034067 | jthompson | james2 | 20021014113403 | | 1034089 | sstanford | stanford | 20021014113407 | | 1034154 | ysheets | sheets | 20021014113416 | | 1034546 | jjmyers | NULL | 20021014113422 | +---------+-----------+----------+----------------+ 8 rows in set (0.00 sec) As you might have noticed, the default ordering used by ORDER BY is ascending order. You can change this by adding the string desc to the end of the clause. For example: mysql> SELECT username, ts FROM acc WHERE ts < now() ORDER BY ts desc; +-----------+----------------+ | username | ts | +-----------+----------------+ | jjmyers | 20021014113422 | | ysheets | 20021014113416 | | sstanford | 20021014113407 | | jthompson | 20021014113403 | | jdoe | 20021014112501 | | jsmith | 20021014112438 | | jime | 20021014112415 |
Quick Hint: If you are looking for best quality webspace to host and run your tomcat application check Vision tomcat hosting services

Comments are closed.