123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. zipcoders-MacBook-Pro:Labs ryans$ cd ..
  2. zipcoders-MacBook-Pro:~ ryans$ mysql.server --start
  3. Usage: mysql.server {start|stop|restart|reload|force-reload|status} [ MySQL server options ]
  4. zipcoders-MacBook-Pro:~ ryans$ mysql -u root -p
  5. Enter password:
  6. Welcome to the MySQL monitor. Commands end with ; or \g.
  7. Your MySQL connection id is 4
  8. Server version: 5.7.22 Homebrew
  9. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  10. Oracle is a registered trademark of Oracle Corporation and/or its
  11. affiliates. Other names may be trademarks of their respective
  12. owners.
  13. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  14. mysql> DROP TABLE IF EXISTS people;
  15. ERROR 1046 (3D000): No database selected
  16. mysql>
  17. mysql> CREATE TABLE people (
  18. -> id INT NOT NULL AUTO_INCREMENT,
  19. -> first_name VARCHAR(255) NOT NULL DEFAULT '',
  20. -> last_name VARCHAR(255) NOT NULL DEFAULT '',
  21. -> mobile VARCHAR(20),
  22. -> birthday DATE DEFAULT NULL,
  23. -> home_id INT DEFAULT NULL,
  24. -> PRIMARY KEY (id));
  25. ERROR 1046 (3D000): No database selected
  26. mysql>
  27. mysql>
  28. mysql> DROP TABLE IF EXISTS homes;
  29. ERROR 1046 (3D000): No database selected
  30. mysql>
  31. mysql> CREATE TABLE homes (
  32. -> id INT NOT NULL AUTO_INCREMENT,
  33. -> address VARCHAR(255) NOT NULL DEFAULT '',
  34. -> homenumber VARCHAR(255) NOT NULL DEFAULT '',
  35. -> PRIMARY KEY (id)
  36. -> );
  37. ERROR 1046 (3D000): No database selected
  38. mysql>
  39. mysql> DROP TABLE IF EXISTS movies;
  40. ERROR 1046 (3D000): No database selected
  41. mysql>
  42. mysql> CREATE TABLE movies (
  43. -> id INT PRIMARY KEY AUTO_INCREMENT,
  44. -> title VARCHAR(100) NOT NULL UNIQUE,
  45. -> runtime SMALLINT NOT NULL,
  46. -> genre VARCHAR(50),
  47. -> imdb_score DECIMAL(10,1),
  48. -> rating VARCHAR(10)
  49. -> );
  50. ERROR 1046 (3D000): No database selected
  51. mysql>
  52. mysql> ALTER TABLE people
  53. -> ADD FOREIGN KEY (home_id)
  54. -> REFERENCES homes(id);
  55. ERROR 1046 (3D000): No database selected
  56. mysql>
  57. mysql>
  58. mysql> create database database;
  59. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1
  60. mysql> mysqul -u root -p database <src/main/resources/schema-h2.sql>;
  61. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysqul -u root -p database <src/main/resources/schema-h2.sql>' at line 1
  62. mysql> mysqul -u root -p database <src/main/resources/schema-h2.sql;>
  63. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysqul -u root -p database <src/main/resources/schema-h2.sql' at line 1
  64. -> mysql -u root -p database <src/main/resources/schema-h2.sql>
  65. -> mysql -u root -p database <src/main/resources/schema-h2.sql;>
  66. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '>
  67. mysql -u root -p database <src/main/resources/schema-h2.sql>
  68. mysql -u root -p ' at line 1
  69. -> > mysql -u root -p database <src/main/resources/schema-h2.sql> mysql -u root -p database <src/main/resources/schema-h2.sql>
  70. -> create
  71. -> q
  72. -> /q
  73. -> \q
  74. Bye
  75. zipcoders-MacBook-Pro:~ ryans$ mysql -u root -p
  76. Enter password:
  77. Welcome to the MySQL monitor. Commands end with ; or \g.
  78. Your MySQL connection id is 5
  79. Server version: 5.7.22 Homebrew
  80. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  81. Oracle is a registered trademark of Oracle Corporation and/or its
  82. affiliates. Other names may be trademarks of their respective
  83. owners.
  84. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  85. mysql> > mysql -u root -p database <src/main/resources/schema-h2.sql>
  86. -> q\
  87. -> \q
  88. Bye
  89. zipcoders-MacBook-Pro:~ ryans$ mysql -u root -p
  90. Enter password:
  91. Welcome to the MySQL monitor. Commands end with ; or \g.
  92. Your MySQL connection id is 6
  93. Server version: 5.7.22 Homebrew
  94. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  95. Oracle is a registered trademark of Oracle Corporation and/or its
  96. affiliates. Other names may be trademarks of their respective
  97. owners.
  98. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  99. mysql> create database dLab;
  100. Query OK, 1 row affected (0.01 sec)
  101. mysql> show databases;
  102. +--------------------+
  103. | Database |
  104. +--------------------+
  105. | information_schema |
  106. | dLab |
  107. | mysql |
  108. | orm_lab |
  109. | performance_schema |
  110. | sys |
  111. +--------------------+
  112. 6 rows in set (0.02 sec)
  113. mysql> mysql -u root -p dLab <src/main/resources/schema-h2.sql
  114. ->
  115. -> mysql -u root -p dLab <src/main/resources/schema-h2.sql>;
  116. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql -u root -p dLab <src/main/resources/schema-h2.sql
  117. mysql -u root -p dLab <' at line 1
  118. mysql> mysql -u root -p dLab <src/main/resources/schema-h2.sql>
  119. ->
  120. -> show databases;
  121. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql -u root -p dLab <src/main/resources/schema-h2.sql>
  122. show databases' at line 1
  123. mysql> use dLab;
  124. Database changed
  125. mysql> show tables
  126. -> show tables;
  127. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'show tables' at line 2
  128. mysql> show tables;
  129. Empty set (0.01 sec)
  130. mysql> src/main/resources/schema-h2.sql
  131. ->
  132. -> DROP TABLE IF EXISTS people;
  133. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'src/main/resources/schema-h2.sql
  134. DROP TABLE IF EXISTS people' at line 1
  135. mysql>
  136. mysql> CREATE TABLE people (
  137. -> id INT NOT NULL AUTO_INCREMENT,
  138. -> first_name VARCHAR(255) NOT NULL DEFAULT '',
  139. -> last_name VARCHAR(255) NOT NULL DEFAULT '',
  140. -> mobile VARCHAR(20),
  141. -> birthday DATE DEFAULT NULL,
  142. -> home_id INT DEFAULT NULL,
  143. -> PRIMARY KEY (id));
  144. Query OK, 0 rows affected (0.08 sec)
  145. mysql>
  146. mysql>
  147. mysql> DROP TABLE IF EXISTS homes;
  148. Query OK, 0 rows affected, 1 warning (0.00 sec)
  149. mysql>
  150. mysql> CREATE TABLE homes (
  151. -> id INT NOT NULL AUTO_INCREMENT,
  152. -> address VARCHAR(255) NOT NULL DEFAULT '',
  153. -> homenumber VARCHAR(255) NOT NULL DEFAULT '',
  154. -> PRIMARY KEY (id)
  155. -> );
  156. Query OK, 0 rows affected (0.02 sec)
  157. mysql>
  158. mysql> DROP TABLE IF EXISTS movies;
  159. Query OK, 0 rows affected, 1 warning (0.00 sec)
  160. mysql>
  161. mysql> CREATE TABLE movies (
  162. -> id INT PRIMARY KEY AUTO_INCREMENT,
  163. -> title VARCHAR(100) NOT NULL UNIQUE,
  164. -> runtime SMALLINT NOT NULL,
  165. -> genre VARCHAR(50),
  166. -> imdb_score DECIMAL(10,1),
  167. -> rating VARCHAR(10)
  168. -> );
  169. Query OK, 0 rows affected (0.01 sec)
  170. mysql>
  171. mysql> ALTER TABLE people
  172. -> ADD FOREIGN KEY (home_id)
  173. -> REFERENCES homes(id);
  174. Query OK, 0 rows affected (0.08 sec)
  175. Records: 0 Duplicates: 0 Warnings: 0
  176. mysql>
  177. mysql> show tables;
  178. +----------------+
  179. | Tables_in_dlab |
  180. +----------------+
  181. | homes |
  182. | movies |
  183. | people |
  184. +----------------+
  185. 3 rows in set (0.00 sec)
  186. mysql> INSERT INTO people (last_name, first_name, mobile, birthday)
  187. -> VALUES ('Smith', 'John', '230-4293', '1973-01-23');
  188. Query OK, 1 row affected (0.02 sec)
  189. mysql>
  190. mysql> INSERT INTO homes (address, homenumber) VALUES ('36 E. Bayberry Rd.Savannah, GA 31404', '565-6895');
  191. Query OK, 1 row affected (0.01 sec)
  192. mysql> INSERT INTO homes (address, homenumber) VALUES ('11 Essex Dr.Farmingdale, NY 11735', '454-4544');
  193. Query OK, 1 row affected (0.01 sec)
  194. mysql> INSERT INTO homes (address, homenumber) VALUES ('920 Arlington Street Clifton, NJ 07011', '985-4515');
  195. Query OK, 1 row affected (0.00 sec)
  196. mysql> INSERT INTO homes (address, homenumber) VALUES ('234 High Street, PA 19159 ', '267-3940');
  197. Query OK, 1 row affected (0.01 sec)
  198. mysql>
  199. mysql>
  200. mysql> INSERT INTO people (last_name, first_name, mobile, birthday, home_id)
  201. -> VALUES ('Carbral', 'Sheeri', '230-4233', '1970-02-23', 2);
  202. Query OK, 1 row affected (0.01 sec)
  203. mysql> INSERT INTO people (last_name, first_name, mobile, birthday, home_id)
  204. -> VALUES ('Sharam', 'Raj', '186-5223', '1980-08-31', 3);
  205. Query OK, 1 row affected (0.00 sec)
  206. mysql> INSERT INTO people (last_name, first_name, mobile, birthday, home_id)
  207. -> VALUES ('Durand', 'Noelle', '395-6161', '1960-07-06', 1);
  208. Query OK, 1 row affected (0.00 sec)
  209. mysql> INSERT INTO people (last_name, first_name, mobile, birthday, home_id)
  210. -> VALUES ('Smith', 'Thomas', '395-6181', '1987-07-06', 1);
  211. Query OK, 1 row affected (0.00 sec)
  212. mysql> INSERT INTO people (last_name, first_name, mobile, birthday, home_id)
  213. -> VALUES ('Smith', 'Jane', '393-6181', '1987-12-06', 3);
  214. Query OK, 1 row affected (0.01 sec)
  215. mysql> INSERT INTO people (last_name, first_name, mobile, birthday, home_id)
  216. -> VALUES ('Brown', 'Doug', '466-6241', '1954-12-07', 3);
  217. Query OK, 1 row affected (0.00 sec)
  218. mysql>
  219. mysql>
  220. mysql> show tables;
  221. +----------------+
  222. | Tables_in_dlab |
  223. +----------------+
  224. | homes |
  225. | movies |
  226. | people |
  227. +----------------+
  228. 3 rows in set (0.00 sec)
  229. mysql> select * from people;
  230. +----+------------+-----------+----------+------------+---------+
  231. | id | first_name | last_name | mobile | birthday | home_id |
  232. +----+------------+-----------+----------+------------+---------+
  233. | 1 | John | Smith | 230-4293 | 1973-01-23 | NULL |
  234. | 2 | Sheeri | Carbral | 230-4233 | 1970-02-23 | 2 |
  235. | 3 | Raj | Sharam | 186-5223 | 1980-08-31 | 3 |
  236. | 4 | Noelle | Durand | 395-6161 | 1960-07-06 | 1 |
  237. | 5 | Thomas | Smith | 395-6181 | 1987-07-06 | 1 |
  238. | 6 | Jane | Smith | 393-6181 | 1987-12-06 | 3 |
  239. | 7 | Doug | Brown | 466-6241 | 1954-12-07 | 3 |
  240. +----+------------+-----------+----------+------------+---------+
  241. 7 rows in set (0.01 sec)
  242. mysql> UPDATE people SET first_name = 'Tony' WHERE id = 1;
  243. Query OK, 1 row affected (0.02 sec)
  244. Rows matched: 1 Changed: 1 Warnings: 0
  245. mysql> UPDATE people SET mobile = '152-9854' WHERE last_name = 'Smith';
  246. Query OK, 3 rows affected (0.01 sec)
  247. Rows matched: 3 Changed: 3 Warnings: 0
  248. mysql> UPDATE people SET birthday = '1955-01-25'
  249. -> WHERE last_name = 'Smith'
  250. -> AND id = 4;
  251. Query OK, 0 rows affected (0.00 sec)
  252. Rows matched: 0 Changed: 0 Warnings: 0
  253. mysql> UPDATE people SET mobile = '333-3333', last_name = 'Johnson'
  254. -> WHERE first_name = 'Noelle' OR first_name = 'Raj';
  255. Query OK, 2 rows affected (0.01 sec)
  256. Rows matched: 2 Changed: 2 Warnings: 0
  257. mysql> SELECT * FROM people;
  258. +----+------------+-----------+----------+------------+---------+
  259. | id | first_name | last_name | mobile | birthday | home_id |
  260. +----+------------+-----------+----------+------------+---------+
  261. | 1 | Tony | Smith | 152-9854 | 1973-01-23 | NULL |
  262. | 2 | Sheeri | Carbral | 230-4233 | 1970-02-23 | 2 |
  263. | 3 | Raj | Johnson | 333-3333 | 1980-08-31 | 3 |
  264. | 4 | Noelle | Johnson | 333-3333 | 1960-07-06 | 1 |
  265. | 5 | Thomas | Smith | 152-9854 | 1987-07-06 | 1 |
  266. | 6 | Jane | Smith | 152-9854 | 1987-12-06 | 3 |
  267. | 7 | Doug | Brown | 466-6241 | 1954-12-07 | 3 |
  268. +----+------------+-----------+----------+------------+---------+
  269. 7 rows in set (0.00 sec)
  270. mysql>
  271. mysql> SELECT * FROM people;
  272. +----+------------+-----------+----------+------------+---------+
  273. | id | first_name | last_name | mobile | birthday | home_id |
  274. +----+------------+-----------+----------+------------+---------+
  275. | 1 | Tony | Smith | 152-9854 | 1973-01-23 | NULL |
  276. | 2 | Sheeri | Carbral | 230-4233 | 1970-02-23 | 2 |
  277. | 3 | Raj | Johnson | 333-3333 | 1980-08-31 | 3 |
  278. | 4 | Noelle | Johnson | 333-3333 | 1960-07-06 | 1 |
  279. | 5 | Thomas | Smith | 152-9854 | 1987-07-06 | 1 |
  280. | 6 | Jane | Smith | 152-9854 | 1987-12-06 | 3 |
  281. | 7 | Doug | Brown | 466-6241 | 1954-12-07 | 3 |
  282. +----+------------+-----------+----------+------------+---------+
  283. 7 rows in set (0.00 sec)
  284. mysql> SELECT COUNT(homenumber) FROM homes;
  285. +-------------------+
  286. | COUNT(homenumber) |
  287. +-------------------+
  288. | 4 |
  289. +-------------------+
  290. 1 row in set (0.02 sec)
  291. mysql> SELECT homenumber FROM homes WHERE id = 1;
  292. +------------+
  293. | homenumber |
  294. +------------+
  295. | 565-6895 |
  296. +------------+
  297. 1 row in set (0.01 sec)
  298. mysql> SELECT COUNT(*) FROM homes;
  299. +----------+
  300. | COUNT(*) |
  301. +----------+
  302. | 4 |
  303. +----------+
  304. 1 row in set (0.01 sec)
  305. mysql> SELECT COUNT(DISTINCT last_name) FROM people;
  306. +---------------------------+
  307. | COUNT(DISTINCT last_name) |
  308. +---------------------------+
  309. | 4 |
  310. +---------------------------+
  311. 1 row in set (0.01 sec)
  312. mysql> show tables home;
  313. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'home' at line 1
  314. mysql> show home;
  315. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'home' at line 1
  316. mysql> select * from homes
  317. -> select * from homes;
  318. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select * from homes' at line 2
  319. mysql> select * from homes;
  320. +----+----------------------------------------+------------+
  321. | id | address | homenumber |
  322. +----+----------------------------------------+------------+
  323. | 1 | 36 E. Bayberry Rd.Savannah, GA 31404 | 565-6895 |
  324. | 2 | 11 Essex Dr.Farmingdale, NY 11735 | 454-4544 |
  325. | 3 | 920 Arlington Street Clifton, NJ 07011 | 985-4515 |
  326. | 4 | 234 High Street, PA 19159 | 267-3940 |
  327. +----+----------------------------------------+------------+
  328. 4 rows in set (0.00 sec)
  329. mysql> SELECT SUM(id), AVG(id) FROM people;
  330. +---------+---------+
  331. | SUM(id) | AVG(id) |
  332. +---------+---------+
  333. | 28 | 4.0000 |
  334. +---------+---------+
  335. 1 row in set (0.01 sec)
  336. mysql> SELECT SUM(id) AS sum, AVG(id) AS avg FROM people;
  337. +------+--------+
  338. | sum | avg |
  339. +------+--------+
  340. | 28 | 4.0000 |
  341. +------+--------+
  342. 1 row in set (0.01 sec)
  343. mysql> SELECT MIN(birthday) FROM people;
  344. +---------------+
  345. | MIN(birthday) |
  346. +---------------+
  347. | 1954-12-07 |
  348. +---------------+
  349. 1 row in set (0.01 sec)
  350. mysql> SELECT UPPER (first_name), LOWER(last_name) FROM people;
  351. +--------------------+------------------+
  352. | UPPER (first_name) | LOWER(last_name) |
  353. +--------------------+------------------+
  354. | TONY | smith |
  355. | SHEERI | carbral |
  356. | RAJ | johnson |
  357. | NOELLE | johnson |
  358. | THOMAS | smith |
  359. | JANE | smith |
  360. | DOUG | brown |
  361. +--------------------+------------------+
  362. 7 rows in set (0.01 sec)
  363. mysql> SELECT REPLACE(last_name, 'a', '1') FROM people;
  364. +------------------------------+
  365. | REPLACE(last_name, 'a', '1') |
  366. +------------------------------+
  367. | Smith |
  368. | C1rbr1l |
  369. | Johnson |
  370. | Johnson |
  371. | Smith |
  372. | Smith |
  373. | Brown |
  374. +------------------------------+
  375. 7 rows in set (0.01 sec)
  376. mysql> SELECT last_name FROM people;
  377. +-----------+
  378. | last_name |
  379. +-----------+
  380. | Smith |
  381. | Carbral |
  382. | Johnson |
  383. | Johnson |
  384. | Smith |
  385. | Smith |
  386. | Brown |
  387. +-----------+
  388. 7 rows in set (0.00 sec)
  389. mysql> INSERT INTO people (first_name, last_name, mobile)
  390. -> VALUES ('Otto', 'Von Count', '656-6548');
  391. Query OK, 1 row affected (0.01 sec)
  392. mysql> SELECT CONCAT(first_name, last_name) FROM people
  393. -> WHERE last_name = 'Smith';
  394. +-------------------------------+
  395. | CONCAT(first_name, last_name) |
  396. +-------------------------------+
  397. | TonySmith |
  398. | ThomasSmith |
  399. | JaneSmith |
  400. +-------------------------------+
  401. 3 rows in set (0.01 sec)
  402. mysql> SELECT CONCAT(first_name, ' ', last_name)
  403. -> FROM people
  404. -> WHERE last_name = 'Smith';
  405. +------------------------------------+
  406. | CONCAT(first_name, ' ', last_name) |
  407. +------------------------------------+
  408. | Tony Smith |
  409. | Thomas Smith |
  410. | Jane Smith |
  411. +------------------------------------+
  412. 3 rows in set (0.01 sec)
  413. mysql> SELECT CONCAT_WS(' ',first_name, last_name, mobile)
  414. -> FROM people WHERE last_name= 'Smith';
  415. +----------------------------------------------+
  416. | CONCAT_WS(' ',first_name, last_name, mobile) |
  417. +----------------------------------------------+
  418. | Tony Smith 152-9854 |
  419. | Thomas Smith 152-9854 |
  420. | Jane Smith 152-9854 |
  421. +----------------------------------------------+
  422. 3 rows in set (0.00 sec)
  423. mysql> SELECT homenumber, LEFT(homenumber, 3), RIGHT(homenumber, 2) FROM homes;
  424. +------------+---------------------+----------------------+
  425. | homenumber | LEFT(homenumber, 3) | RIGHT(homenumber, 2) |
  426. +------------+---------------------+----------------------+
  427. | 565-6895 | 565 | 95 |
  428. | 454-4544 | 454 | 44 |
  429. | 985-4515 | 985 | 15 |
  430. | 267-3940 | 267 | 40 |
  431. +------------+---------------------+----------------------+
  432. 4 rows in set (0.00 sec)
  433. mysql> SELECT homenumber, LEFT(homenumber, 3), RIGHT(homenumber, 1) FROM homes; +------------+---------------------+----------------------+
  434. | homenumber | LEFT(homenumber, 3) | RIGHT(homenumber, 1) |
  435. +------------+---------------------+----------------------+
  436. | 565-6895 | 565 | 5 |
  437. | 454-4544 | 454 | 4 |
  438. | 985-4515 | 985 | 5 |
  439. | 267-3940 | 267 | 0 |
  440. +------------+---------------------+----------------------+
  441. 4 rows in set (0.00 sec)
  442. mysql> SELECT homenumber, LEFT(homenumber, 3), lefT(homenumber, 1) FROM homes;
  443. +------------+---------------------+---------------------+
  444. | homenumber | LEFT(homenumber, 3) | lefT(homenumber, 1) |
  445. +------------+---------------------+---------------------+
  446. | 565-6895 | 565 | 5 |
  447. | 454-4544 | 454 | 4 |
  448. | 985-4515 | 985 | 9 |
  449. | 267-3940 | 267 | 2 |
  450. +------------+---------------------+---------------------+
  451. 4 rows in set (0.00 sec)
  452. mysql> SELECT homenumber, LEFT(homenumber, 3), lefT(homenumber, 3) FROM homes;
  453. +------------+---------------------+---------------------+
  454. | homenumber | LEFT(homenumber, 3) | lefT(homenumber, 3) |
  455. +------------+---------------------+---------------------+
  456. | 565-6895 | 565 | 565 |
  457. | 454-4544 | 454 | 454 |
  458. | 985-4515 | 985 | 985 |
  459. | 267-3940 | 267 | 267 |
  460. +------------+---------------------+---------------------+
  461. 4 rows in set (0.00 sec)
  462. mysql> SELECT LENGTH(address), CHAR_LENGTH(address) FROM homes;
  463. +-----------------+----------------------+
  464. | LENGTH(address) | CHAR_LENGTH(address) |
  465. +-----------------+----------------------+
  466. | 36 | 36 |
  467. | 33 | 33 |
  468. | 38 | 38 |
  469. | 26 | 26 |
  470. +-----------------+----------------------+
  471. 4 rows in set (0.01 sec)
  472. mysql> SELECT first_name, last_name, YEAR(birthday) FROM people WHERE birthday >= '1970-07-06' AND birthday<='1987-07-06';
  473. +------------+-----------+----------------+
  474. | first_name | last_name | YEAR(birthday) |
  475. +------------+-----------+----------------+
  476. | Tony | Smith | 1973 |
  477. | Raj | Johnson | 1980 |
  478. | Thomas | Smith | 1987 |
  479. +------------+-----------+----------------+
  480. 3 rows in set (0.01 sec)
  481. mysql> SELECT first_name, last_name, YEAR(birthday) FROM people WHERE birthday >= '1970-07-06' AND birthday<='1987-07-06';
  482. +------------+-----------+----------------+
  483. | first_name | last_name | YEAR(birthday) |
  484. +------------+-----------+----------------+
  485. | Tony | Smith | 1973 |
  486. | Raj | Johnson | 1980 |
  487. | Thomas | Smith | 1987 |
  488. +------------+-----------+----------------+
  489. 3 rows in set (0.00 sec)
  490. mysql> SELECT first_name, birthday FROM people WHERE first_name='Thomas' OR first_name='Raj' OR first_name='Sheeri';
  491. +------------+------------+
  492. | first_name | birthday |
  493. +------------+------------+
  494. | Sheeri | 1970-02-23 |
  495. | Raj | 1980-08-31 |
  496. | Thomas | 1987-07-06 |
  497. +------------+------------+
  498. 3 rows in set (0.00 sec)
  499. mysql> SELECT first_name, birthday FROM people WHERE first_name IN ('Noelle', 'Thomas', 'Raj');
  500. +------------+------------+
  501. | first_name | birthday |
  502. +------------+------------+
  503. | Raj | 1980-08-31 |
  504. | Noelle | 1960-07-06 |
  505. | Thomas | 1987-07-06 |
  506. +------------+------------+
  507. 3 rows in set (0.01 sec)
  508. mysql> SELECT first_name FROM people WHERE RIGHT(first_name,1)='e';
  509. +------------+
  510. | first_name |
  511. +------------+
  512. | Noelle |
  513. | Jane |
  514. +------------+
  515. 2 rows in set (0.00 sec)
  516. mysql>
  517. mysql> select * from people;
  518. +----+------------+-----------+----------+------------+---------+
  519. | id | first_name | last_name | mobile | birthday | home_id |
  520. +----+------------+-----------+----------+------------+---------+
  521. | 1 | Tony | Smith | 152-9854 | 1973-01-23 | NULL |
  522. | 2 | Sheeri | Carbral | 230-4233 | 1970-02-23 | 2 |
  523. | 3 | Raj | Johnson | 333-3333 | 1980-08-31 | 3 |
  524. | 4 | Noelle | Johnson | 333-3333 | 1960-07-06 | 1 |
  525. | 5 | Thomas | Smith | 152-9854 | 1987-07-06 | 1 |
  526. | 6 | Jane | Smith | 152-9854 | 1987-12-06 | 3 |
  527. | 7 | Doug | Brown | 466-6241 | 1954-12-07 | 3 |
  528. | 8 | Otto | Von Count | 656-6548 | NULL | NULL |
  529. +----+------------+-----------+----------+------------+---------+
  530. 8 rows in set (0.00 sec)
  531. mysql> SELECT first_name FROM people WHERE first_name LIKE '%j';
  532. +------------+
  533. | first_name |
  534. +------------+
  535. | Raj |
  536. +------------+
  537. 1 row in set (0.01 sec)
  538. mysql> SELECT first_name FROM people WHERE first_name LIKE '%o%';
  539. +------------+
  540. | first_name |
  541. +------------+
  542. | Tony |
  543. | Noelle |
  544. | Thomas |
  545. | Doug |
  546. | Otto |
  547. +------------+
  548. 5 rows in set (0.00 sec)
  549. mysql> SELECT first_name FROM people WHERE first_name NOT LIKE '%o%';
  550. +------------+
  551. | first_name |
  552. +------------+
  553. | Sheeri |
  554. | Raj |
  555. | Jane |
  556. +------------+
  557. 3 rows in set (0.01 sec)
  558. mysql> SELECT COUNT(*) FROM people;
  559. +----------+
  560. | COUNT(*) |
  561. +----------+
  562. | 8 |
  563. +----------+
  564. 1 row in set (0.00 sec)
  565. mysql> SELECT last_name, COUNT(*) FROM people GROUP BY last_name;
  566. +-----------+----------+
  567. | last_name | COUNT(*) |
  568. +-----------+----------+
  569. | Brown | 1 |
  570. | Carbral | 1 |
  571. | Johnson | 2 |
  572. | Smith | 3 |
  573. | Von Count | 1 |
  574. +-----------+----------+
  575. 5 rows in set (0.01 sec)
  576. mysql> SELECT last_name, GROUP_CONCAT(mobile) FROM people GROUP BY last_name;
  577. +-----------+----------------------------+
  578. | last_name | GROUP_CONCAT(mobile) |
  579. +-----------+----------------------------+
  580. | Brown | 466-6241 |
  581. | Carbral | 230-4233 |
  582. | Johnson | 333-3333,333-3333 |
  583. | Smith | 152-9854,152-9854,152-9854 |
  584. | Von Count | 656-6548 |
  585. +-----------+----------------------------+
  586. 5 rows in set (0.00 sec)
  587. mysql> SELECT last_name, GROUP_CONCAT(mobile SEPARATOR ' and ') FROM people GROUP BY last_name;
  588. +-----------+----------------------------------------+
  589. | last_name | GROUP_CONCAT(mobile SEPARATOR ' and ') |
  590. +-----------+----------------------------------------+
  591. | Brown | 466-6241 |
  592. | Carbral | 230-4233 |
  593. | Johnson | 333-3333 and 333-3333 |
  594. | Smith | 152-9854 and 152-9854 and 152-9854 |
  595. | Von Count | 656-6548 |
  596. +-----------+----------------------------------------+
  597. 5 rows in set (0.00 sec)
  598. mysql> SELECT last_name, GROUP_CONCAT(mobile SEPARATOR ' and ') FROM people GROUP BY last_name HAVING COUNT(*)>1;
  599. +-----------+----------------------------------------+
  600. | last_name | GROUP_CONCAT(mobile SEPARATOR ' and ') |
  601. +-----------+----------------------------------------+
  602. | Johnson | 333-3333 and 333-3333 |
  603. | Smith | 152-9854 and 152-9854 and 152-9854 |
  604. +-----------+----------------------------------------+
  605. 2 rows in set (0.00 sec)
  606. mysql> SELECT last_name, GROUP_CONCAT(mobile SEPARATOR ' and ') FROM people WHERE last_name != 'Cabral' GROUP BY last_name HAVING COUNT(*)>1;
  607. +-----------+----------------------------------------+
  608. | last_name | GROUP_CONCAT(mobile SEPARATOR ' and ') |
  609. +-----------+----------------------------------------+
  610. | Johnson | 333-3333 and 333-3333 |
  611. | Smith | 152-9854 and 152-9854 and 152-9854 |
  612. +-----------+----------------------------------------+
  613. 2 rows in set (0.00 sec)
  614. mysql> SELECT last_name, GROUP_CONCAT(mobile SEPARATOR ' and ') FROM people WHERE last_name != 'johnson' GROUP BY last_name HAVING COUNT(*)>1;
  615. +-----------+----------------------------------------+
  616. | last_name | GROUP_CONCAT(mobile SEPARATOR ' and ') |
  617. +-----------+----------------------------------------+
  618. | Smith | 152-9854 and 152-9854 and 152-9854 |
  619. +-----------+----------------------------------------+
  620. 1 row in set (0.00 sec)
  621. mysql> SELECT first_name, birthday FROM people ORDER BY birthday;
  622. +------------+------------+
  623. | first_name | birthday |
  624. +------------+------------+
  625. | Otto | NULL |
  626. | Doug | 1954-12-07 |
  627. | Noelle | 1960-07-06 |
  628. | Sheeri | 1970-02-23 |
  629. | Tony | 1973-01-23 |
  630. | Raj | 1980-08-31 |
  631. | Thomas | 1987-07-06 |
  632. | Jane | 1987-12-06 |
  633. +------------+------------+
  634. 8 rows in set (0.00 sec)
  635. mysql> SELECT first_name, birthday FROM people ORDER BY birthday DESC;
  636. +------------+------------+
  637. | first_name | birthday |
  638. +------------+------------+
  639. | Jane | 1987-12-06 |
  640. | Thomas | 1987-07-06 |
  641. | Raj | 1980-08-31 |
  642. | Tony | 1973-01-23 |
  643. | Sheeri | 1970-02-23 |
  644. | Noelle | 1960-07-06 |
  645. | Doug | 1954-12-07 |
  646. | Otto | NULL |
  647. +------------+------------+
  648. 8 rows in set (0.00 sec)
  649. mysql> SELECT first_name, last_name FROM people ORDER BY last_name, first_name;
  650. +------------+-----------+
  651. | first_name | last_name |
  652. +------------+-----------+
  653. | Doug | Brown |
  654. | Sheeri | Carbral |
  655. | Noelle | Johnson |
  656. | Raj | Johnson |
  657. | Jane | Smith |
  658. | Thomas | Smith |
  659. | Tony | Smith |
  660. | Otto | Von Count |
  661. +------------+-----------+
  662. 8 rows in set (0.00 sec)
  663. mysql> SELECT first_name, birthday FROM people ORDER BY birthday DESC LIMIT 3;
  664. +------------+------------+
  665. | first_name | birthday |
  666. +------------+------------+
  667. | Jane | 1987-12-06 |
  668. | Thomas | 1987-07-06 |
  669. | Raj | 1980-08-31 |
  670. +------------+------------+
  671. 3 rows in set (0.00 sec)
  672. mysql> SELECT first_name, MONTHNAME(birthday) as mon, birthday FROM people ORDER BY MONTH(birthday);
  673. +------------+----------+------------+
  674. | first_name | mon | birthday |
  675. +------------+----------+------------+
  676. | Otto | NULL | NULL |
  677. | Tony | January | 1973-01-23 |
  678. | Sheeri | February | 1970-02-23 |
  679. | Noelle | July | 1960-07-06 |
  680. | Thomas | July | 1987-07-06 |
  681. | Raj | August | 1980-08-31 |
  682. | Jane | December | 1987-12-06 |
  683. | Doug | December | 1954-12-07 |
  684. +------------+----------+------------+
  685. 8 rows in set (0.01 sec)
  686. mysql> SELECT last_name, COUNT(*) FROM people GROUP BY last_name;
  687. +-----------+----------+
  688. | last_name | COUNT(*) |
  689. +-----------+----------+
  690. | Brown | 1 |
  691. | Carbral | 1 |
  692. | Johnson | 2 |
  693. | Smith | 3 |
  694. | Von Count | 1 |
  695. +-----------+----------+
  696. 5 rows in set (0.00 sec)
  697. mysql> SELECT last_name, COUNT(*) FROM people GROUP BY last_name ORDER BY NULL;
  698. +-----------+----------+
  699. | last_name | COUNT(*) |
  700. +-----------+----------+
  701. | Smith | 3 |
  702. | Carbral | 1 |
  703. | Johnson | 2 |
  704. | Brown | 1 |
  705. | Von Count | 1 |
  706. +-----------+----------+
  707. 5 rows in set (0.01 sec)
  708. mysql> SELECT last_name, COUNT(*) FROM people GROUP BY last_name ORDER BY NULL;
  709. +-----------+----------+
  710. | last_name | COUNT(*) |
  711. +-----------+----------+
  712. | Smith | 3 |
  713. | Carbral | 1 |
  714. | Johnson | 2 |
  715. | Brown | 1 |
  716. | Von Count | 1 |
  717. +-----------+----------+
  718. 5 rows in set (0.00 sec)
  719. mysql> select * from people;
  720. +----+------------+-----------+----------+------------+---------+
  721. | id | first_name | last_name | mobile | birthday | home_id |
  722. +----+------------+-----------+----------+------------+---------+
  723. | 1 | Tony | Smith | 152-9854 | 1973-01-23 | NULL |
  724. | 2 | Sheeri | Carbral | 230-4233 | 1970-02-23 | 2 |
  725. | 3 | Raj | Johnson | 333-3333 | 1980-08-31 | 3 |
  726. | 4 | Noelle | Johnson | 333-3333 | 1960-07-06 | 1 |
  727. | 5 | Thomas | Smith | 152-9854 | 1987-07-06 | 1 |
  728. | 6 | Jane | Smith | 152-9854 | 1987-12-06 | 3 |
  729. | 7 | Doug | Brown | 466-6241 | 1954-12-07 | 3 |
  730. | 8 | Otto | Von Count | 656-6548 | NULL | NULL |
  731. +----+------------+-----------+----------+------------+---------+
  732. 8 rows in set (0.00 sec)
  733. mysql> INSERT INTO people (first_name, last_name, birthday, home_id)
  734. -> VALUES ('John', 'Smith', '1998-04-07', 4),
  735. -> ('Maya', 'Wasserman' , NULL, 4),
  736. -> ('Paul', 'Thompson', '1996-05-27', 1);
  737. Query OK, 3 rows affected (0.02 sec)
  738. Records: 3 Duplicates: 0 Warnings: 0
  739. mysql> DELETE FROM people WHERE first_name='Maya';
  740. Query OK, 1 row affected (0.01 sec)
  741. mysql> select * from people;
  742. +----+------------+-----------+----------+------------+---------+
  743. | id | first_name | last_name | mobile | birthday | home_id |
  744. +----+------------+-----------+----------+------------+---------+
  745. | 1 | Tony | Smith | 152-9854 | 1973-01-23 | NULL |
  746. | 2 | Sheeri | Carbral | 230-4233 | 1970-02-23 | 2 |
  747. | 3 | Raj | Johnson | 333-3333 | 1980-08-31 | 3 |
  748. | 4 | Noelle | Johnson | 333-3333 | 1960-07-06 | 1 |
  749. | 5 | Thomas | Smith | 152-9854 | 1987-07-06 | 1 |
  750. | 6 | Jane | Smith | 152-9854 | 1987-12-06 | 3 |
  751. | 7 | Doug | Brown | 466-6241 | 1954-12-07 | 3 |
  752. | 8 | Otto | Von Count | 656-6548 | NULL | NULL |
  753. | 9 | John | Smith | NULL | 1998-04-07 | 4 |
  754. | 11 | Paul | Thompson | NULL | 1996-05-27 | 1 |
  755. +----+------------+-----------+----------+------------+---------+
  756. 10 rows in set (0.00 sec)
  757. mysql> INSERT INTO people (first_name, last_name, birthday)
  758. -> VALUES ('Eli', 'Kramer', '1984-01-15');
  759. Query OK, 1 row affected (0.01 sec)
  760. mysql> select * from people;
  761. +----+------------+-----------+----------+------------+---------+
  762. | id | first_name | last_name | mobile | birthday | home_id |
  763. +----+------------+-----------+----------+------------+---------+
  764. | 1 | Tony | Smith | 152-9854 | 1973-01-23 | NULL |
  765. | 2 | Sheeri | Carbral | 230-4233 | 1970-02-23 | 2 |
  766. | 3 | Raj | Johnson | 333-3333 | 1980-08-31 | 3 |
  767. | 4 | Noelle | Johnson | 333-3333 | 1960-07-06 | 1 |
  768. | 5 | Thomas | Smith | 152-9854 | 1987-07-06 | 1 |
  769. | 6 | Jane | Smith | 152-9854 | 1987-12-06 | 3 |
  770. | 7 | Doug | Brown | 466-6241 | 1954-12-07 | 3 |
  771. | 8 | Otto | Von Count | 656-6548 | NULL | NULL |
  772. | 9 | John | Smith | NULL | 1998-04-07 | 4 |
  773. | 11 | Paul | Thompson | NULL | 1996-05-27 | 1 |
  774. | 12 | Eli | Kramer | NULL | 1984-01-15 | NULL |
  775. +----+------------+-----------+----------+------------+---------+
  776. 11 rows in set (0.00 sec)
  777. mysql> select * from homes;
  778. +----+----------------------------------------+------------+
  779. | id | address | homenumber |
  780. +----+----------------------------------------+------------+
  781. | 1 | 36 E. Bayberry Rd.Savannah, GA 31404 | 565-6895 |
  782. | 2 | 11 Essex Dr.Farmingdale, NY 11735 | 454-4544 |
  783. | 3 | 920 Arlington Street Clifton, NJ 07011 | 985-4515 |
  784. | 4 | 234 High Street, PA 19159 | 267-3940 |
  785. +----+----------------------------------------+------------+
  786. 4 rows in set (0.01 sec)
  787. mysql> SELECT p.first_name, h.address
  788. -> FROM people p
  789. -> INNER JOIN homes h on (p.home_id = h.id);
  790. +------------+----------------------------------------+
  791. | first_name | address |
  792. +------------+----------------------------------------+
  793. | Noelle | 36 E. Bayberry Rd.Savannah, GA 31404 |
  794. | Thomas | 36 E. Bayberry Rd.Savannah, GA 31404 |
  795. | Paul | 36 E. Bayberry Rd.Savannah, GA 31404 |
  796. | Sheeri | 11 Essex Dr.Farmingdale, NY 11735 |
  797. | Raj | 920 Arlington Street Clifton, NJ 07011 |
  798. | Jane | 920 Arlington Street Clifton, NJ 07011 |
  799. | Doug | 920 Arlington Street Clifton, NJ 07011 |
  800. | John | 234 High Street, PA 19159 |
  801. +------------+----------------------------------------+
  802. 8 rows in set (0.01 sec)
  803. mysql> SELECT first_name, last_name
  804. -> FROM people p
  805. -> INNER JOIN homes h on (p.home_id = h.id)
  806. -> WHERE p.HOME_ID = 1;
  807. +------------+-----------+
  808. | first_name | last_name |
  809. +------------+-----------+
  810. | Noelle | Johnson |
  811. | Thomas | Smith |
  812. | Paul | Thompson |
  813. +------------+-----------+
  814. 3 rows in set (0.01 sec)
  815. mysql> select * from people;
  816. +----+------------+-----------+----------+------------+---------+
  817. | id | first_name | last_name | mobile | birthday | home_id |
  818. +----+------------+-----------+----------+------------+---------+
  819. | 1 | Tony | Smith | 152-9854 | 1973-01-23 | NULL |
  820. | 2 | Sheeri | Carbral | 230-4233 | 1970-02-23 | 2 |
  821. | 3 | Raj | Johnson | 333-3333 | 1980-08-31 | 3 |
  822. | 4 | Noelle | Johnson | 333-3333 | 1960-07-06 | 1 |
  823. | 5 | Thomas | Smith | 152-9854 | 1987-07-06 | 1 |
  824. | 6 | Jane | Smith | 152-9854 | 1987-12-06 | 3 |
  825. | 7 | Doug | Brown | 466-6241 | 1954-12-07 | 3 |
  826. | 8 | Otto | Von Count | 656-6548 | NULL | NULL |
  827. | 9 | John | Smith | NULL | 1998-04-07 | 4 |
  828. | 11 | Paul | Thompson | NULL | 1996-05-27 | 1 |
  829. | 12 | Eli | Kramer | NULL | 1984-01-15 | NULL |
  830. +----+------------+-----------+----------+------------+---------+
  831. 11 rows in set (0.00 sec)
  832. mysql> SELECT p.*, h.address, h.homenumber
  833. -> FROM people p
  834. -> INNER JOIN homes h on (p.home_id = h.id)
  835. -> WHERE p.first_name LIKE '%e%';
  836. +----+------------+-----------+----------+------------+---------+----------------------------------------+------------+
  837. | id | first_name | last_name | mobile | birthday | home_id | address | homenumber |
  838. +----+------------+-----------+----------+------------+---------+----------------------------------------+------------+
  839. | 2 | Sheeri | Carbral | 230-4233 | 1970-02-23 | 2 | 11 Essex Dr.Farmingdale, NY 11735 | 454-4544 |
  840. | 4 | Noelle | Johnson | 333-3333 | 1960-07-06 | 1 | 36 E. Bayberry Rd.Savannah, GA 31404 | 565-6895 |
  841. | 6 | Jane | Smith | 152-9854 | 1987-12-06 | 3 | 920 Arlington Street Clifton, NJ 07011 | 985-4515 |
  842. +----+------------+-----------+----------+------------+---------+----------------------------------------+------------+
  843. 3 rows in set (0.02 sec)
  844. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'people' at line 1
  845. mysql> select * from birthday;
  846. mysql> select * from people;
  847. +----+------------+-----------+----------+------------+---------+
  848. | id | first_name | last_name | mobile | birthday | home_id |
  849. +----+------------+-----------+----------+------------+---------+
  850. | 1 | Tony | Smith | 152-9854 | 1973-01-23 | NULL |
  851. | 2 | Sheeri | Carbral | 230-4233 | 1970-02-23 | 2 |
  852. | 3 | Raj | Johnson | 333-3333 | 1980-08-31 | 3 |
  853. | 4 | Noelle | Johnson | 333-3333 | 1960-07-06 | 1 |
  854. | 5 | Thomas | Smith | 152-9854 | 1987-07-06 | 1 |
  855. | 6 | Jane | Smith | 152-9854 | 1987-12-06 | 3 |
  856. | 7 | Doug | Brown | 466-6241 | 1954-12-07 | 3 |
  857. | 8 | Otto | Von Count | 656-6548 | NULL | NULL |
  858. | 9 | John | Smith | NULL | 1998-04-07 | 4 |
  859. | 11 | Paul | Thompson | NULL | 1996-05-27 | 1 |
  860. | 12 | Eli | Kramer | NULL | 1984-01-15 | NULL |
  861. +----+------------+-----------+----------+------------+---------+
  862. 11 rows in set (0.00 sec)
  863. mysql> select * from people order by birthday;
  864. +----+------------+-----------+----------+------------+---------+
  865. | id | first_name | last_name | mobile | birthday | home_id |
  866. +----+------------+-----------+----------+------------+---------+
  867. | 8 | Otto | Von Count | 656-6548 | NULL | NULL |
  868. | 7 | Doug | Brown | 466-6241 | 1954-12-07 | 3 |
  869. | 4 | Noelle | Johnson | 333-3333 | 1960-07-06 | 1 |
  870. | 2 | Sheeri | Carbral | 230-4233 | 1970-02-23 | 2 |
  871. | 1 | Tony | Smith | 152-9854 | 1973-01-23 | NULL |
  872. | 3 | Raj | Johnson | 333-3333 | 1980-08-31 | 3 |
  873. | 12 | Eli | Kramer | NULL | 1984-01-15 | NULL |
  874. | 5 | Thomas | Smith | 152-9854 | 1987-07-06 | 1 |
  875. | 6 | Jane | Smith | 152-9854 | 1987-12-06 | 3 |
  876. | 11 | Paul | Thompson | NULL | 1996-05-27 | 1 |
  877. | 9 | John | Smith | NULL | 1998-04-07 | 4 |
  878. +----+------------+-----------+----------+------------+---------+
  879. 11 rows in set (0.00 sec)
  880. mysql> select * from people order by birthday desc;
  881. +----+------------+-----------+----------+------------+---------+
  882. | id | first_name | last_name | mobile | birthday | home_id |
  883. +----+------------+-----------+----------+------------+---------+
  884. | 9 | John | Smith | NULL | 1998-04-07 | 4 |
  885. | 11 | Paul | Thompson | NULL | 1996-05-27 | 1 |
  886. | 6 | Jane | Smith | 152-9854 | 1987-12-06 | 3 |
  887. | 5 | Thomas | Smith | 152-9854 | 1987-07-06 | 1 |
  888. | 12 | Eli | Kramer | NULL | 1984-01-15 | NULL |
  889. | 3 | Raj | Johnson | 333-3333 | 1980-08-31 | 3 |
  890. | 1 | Tony | Smith | 152-9854 | 1973-01-23 | NULL |
  891. | 2 | Sheeri | Carbral | 230-4233 | 1970-02-23 | 2 |
  892. | 4 | Noelle | Johnson | 333-3333 | 1960-07-06 | 1 |
  893. | 7 | Doug | Brown | 466-6241 | 1954-12-07 | 3 |
  894. | 8 | Otto | Von Count | 656-6548 | NULL | NULL |
  895. +----+------------+-----------+----------+------------+---------+
  896. 11 rows in set (0.00 sec)
  897. mysql> select * from people order by birthday desc where birthday not like %;
  898. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where birthday not like %' at line 1
  899. mysql> select * from people order by birthday DESC LIMIT 11;
  900. +----+------------+-----------+----------+------------+---------+
  901. | id | first_name | last_name | mobile | birthday | home_id |
  902. +----+------------+-----------+----------+------------+---------+
  903. | 9 | John | Smith | NULL | 1998-04-07 | 4 |
  904. | 11 | Paul | Thompson | NULL | 1996-05-27 | 1 |
  905. | 6 | Jane | Smith | 152-9854 | 1987-12-06 | 3 |
  906. | 5 | Thomas | Smith | 152-9854 | 1987-07-06 | 1 |
  907. | 12 | Eli | Kramer | NULL | 1984-01-15 | NULL |
  908. | 3 | Raj | Johnson | 333-3333 | 1980-08-31 | 3 |
  909. | 1 | Tony | Smith | 152-9854 | 1973-01-23 | NULL |
  910. | 2 | Sheeri | Carbral | 230-4233 | 1970-02-23 | 2 |
  911. | 4 | Noelle | Johnson | 333-3333 | 1960-07-06 | 1 |
  912. | 7 | Doug | Brown | 466-6241 | 1954-12-07 | 3 |
  913. | 8 | Otto | Von Count | 656-6548 | NULL | NULL |
  914. +----+------------+-----------+----------+------------+---------+
  915. 11 rows in set (0.00 sec)
  916. mysql> select * from people order by birthday DESC LIMIT 10;
  917. +----+------------+-----------+----------+------------+---------+
  918. | id | first_name | last_name | mobile | birthday | home_id |
  919. +----+------------+-----------+----------+------------+---------+
  920. | 9 | John | Smith | NULL | 1998-04-07 | 4 |
  921. | 11 | Paul | Thompson | NULL | 1996-05-27 | 1 |
  922. | 6 | Jane | Smith | 152-9854 | 1987-12-06 | 3 |
  923. | 5 | Thomas | Smith | 152-9854 | 1987-07-06 | 1 |
  924. | 12 | Eli | Kramer | NULL | 1984-01-15 | NULL |
  925. | 3 | Raj | Johnson | 333-3333 | 1980-08-31 | 3 |
  926. | 1 | Tony | Smith | 152-9854 | 1973-01-23 | NULL |
  927. | 2 | Sheeri | Carbral | 230-4233 | 1970-02-23 | 2 |
  928. | 4 | Noelle | Johnson | 333-3333 | 1960-07-06 | 1 |
  929. | 7 | Doug | Brown | 466-6241 | 1954-12-07 | 3 |
  930. +----+------------+-----------+----------+------------+---------+
  931. 10 rows in set (0.00 sec)
  932. mysql> select * from people order by birthday MONTH DESC LIMIT 10;
  933. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'MONTH DESC LIMIT 10' at line 1
  934. mysql> select * from people order by MONTH(birthday) DESC LIMIT 10;
  935. +----+------------+-----------+----------+------------+---------+
  936. | id | first_name | last_name | mobile | birthday | home_id |
  937. +----+------------+-----------+----------+------------+---------+
  938. | 6 | Jane | Smith | 152-9854 | 1987-12-06 | 3 |
  939. | 7 | Doug | Brown | 466-6241 | 1954-12-07 | 3 |
  940. | 3 | Raj | Johnson | 333-3333 | 1980-08-31 | 3 |
  941. | 4 | Noelle | Johnson | 333-3333 | 1960-07-06 | 1 |
  942. | 5 | Thomas | Smith | 152-9854 | 1987-07-06 | 1 |
  943. | 11 | Paul | Thompson | NULL | 1996-05-27 | 1 |
  944. | 9 | John | Smith | NULL | 1998-04-07 | 4 |
  945. | 2 | Sheeri | Carbral | 230-4233 | 1970-02-23 | 2 |
  946. | 1 | Tony | Smith | 152-9854 | 1973-01-23 | NULL |
  947. | 12 | Eli | Kramer | NULL | 1984-01-15 | NULL |
  948. +----+------------+-----------+----------+------------+---------+
  949. 10 rows in set (0.00 sec)
  950. mysql> select first_name, last_name,address, MONTHNAME(birthday) as mon, birthday from people order by MONTH(birthday) DESC LIMIT 10;
  951. ERROR 1054 (42S22): Unknown column 'address' in 'field list'
  952. mysql> select first_name, last_name, MONTHNAME(birthday) as mon, birthday from people order by MONTH(birthday) DESC LIMIT 10;
  953. +------------+-----------+----------+------------+
  954. | first_name | last_name | mon | birthday |
  955. +------------+-----------+----------+------------+
  956. | Jane | Smith | December | 1987-12-06 |
  957. | Doug | Brown | December | 1954-12-07 |
  958. | Raj | Johnson | August | 1980-08-31 |
  959. | Noelle | Johnson | July | 1960-07-06 |
  960. | Thomas | Smith | July | 1987-07-06 |
  961. | Paul | Thompson | May | 1996-05-27 |
  962. | John | Smith | April | 1998-04-07 |
  963. | Sheeri | Carbral | February | 1970-02-23 |
  964. | Tony | Smith | January | 1973-01-23 |
  965. | Eli | Kramer | January | 1984-01-15 |
  966. +------------+-----------+----------+------------+
  967. 10 rows in set (0.00 sec)
  968. mysql> select first_name, last_name, MONTHNAME(birthday) as mon, birthday from people order by MONTH(birthday) aSC LIMIT 10;
  969. +------------+-----------+----------+------------+
  970. | first_name | last_name | mon | birthday |
  971. +------------+-----------+----------+------------+
  972. | Otto | Von Count | NULL | NULL |
  973. | Tony | Smith | January | 1973-01-23 |
  974. | Eli | Kramer | January | 1984-01-15 |
  975. | Sheeri | Carbral | February | 1970-02-23 |
  976. | John | Smith | April | 1998-04-07 |
  977. | Paul | Thompson | May | 1996-05-27 |
  978. | Noelle | Johnson | July | 1960-07-06 |
  979. | Thomas | Smith | July | 1987-07-06 |
  980. | Raj | Johnson | August | 1980-08-31 |
  981. | Jane | Smith | December | 1987-12-06 |
  982. +------------+-----------+----------+------------+
  983. 10 rows in set (0.00 sec)
  984. mysql> delete from people where birthday is null;
  985. Query OK, 1 row affected (0.01 sec)
  986. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'people' at line 1
  987. mysql> select * from people;
  988. +----+------------+-----------+----------+------------+---------+
  989. | id | first_name | last_name | mobile | birthday | home_id |
  990. +----+------------+-----------+----------+------------+---------+
  991. | 1 | Tony | Smith | 152-9854 | 1973-01-23 | NULL |
  992. | 2 | Sheeri | Carbral | 230-4233 | 1970-02-23 | 2 |
  993. | 3 | Raj | Johnson | 333-3333 | 1980-08-31 | 3 |
  994. | 4 | Noelle | Johnson | 333-3333 | 1960-07-06 | 1 |
  995. | 5 | Thomas | Smith | 152-9854 | 1987-07-06 | 1 |
  996. | 6 | Jane | Smith | 152-9854 | 1987-12-06 | 3 |
  997. | 7 | Doug | Brown | 466-6241 | 1954-12-07 | 3 |
  998. | 9 | John | Smith | NULL | 1998-04-07 | 4 |
  999. | 11 | Paul | Thompson | NULL | 1996-05-27 | 1 |
  1000. | 12 | Eli | Kramer | NULL | 1984-01-15 | NULL |
  1001. +----+------------+-----------+----------+------------+---------+
  1002. 10 rows in set (0.00 sec)
  1003. mysql> select first_name, last_name, MONTHNAME(birthday) as mon, birthday from people order by MONTH(birthday) aSC LIMIT 10;
  1004. +------------+-----------+----------+------------+
  1005. | first_name | last_name | mon | birthday |
  1006. +------------+-----------+----------+------------+
  1007. | Tony | Smith | January | 1973-01-23 |
  1008. | Eli | Kramer | January | 1984-01-15 |
  1009. | Sheeri | Carbral | February | 1970-02-23 |
  1010. | John | Smith | April | 1998-04-07 |
  1011. | Paul | Thompson | May | 1996-05-27 |
  1012. | Noelle | Johnson | July | 1960-07-06 |
  1013. | Thomas | Smith | July | 1987-07-06 |
  1014. | Raj | Johnson | August | 1980-08-31 |
  1015. | Jane | Smith | December | 1987-12-06 |
  1016. | Doug | Brown | December | 1954-12-07 |
  1017. +------------+-----------+----------+------------+
  1018. 10 rows in set (0.00 sec)
  1019. mysql> select first_name, last_name, MONTHNAME(birthday) as mon, birthday from people order by MONTH(birthday) aSC;
  1020. +------------+-----------+----------+------------+
  1021. | first_name | last_name | mon | birthday |
  1022. +------------+-----------+----------+------------+
  1023. | Tony | Smith | January | 1973-01-23 |
  1024. | Eli | Kramer | January | 1984-01-15 |
  1025. | Sheeri | Carbral | February | 1970-02-23 |
  1026. | John | Smith | April | 1998-04-07 |
  1027. | Paul | Thompson | May | 1996-05-27 |
  1028. | Noelle | Johnson | July | 1960-07-06 |
  1029. | Thomas | Smith | July | 1987-07-06 |
  1030. | Raj | Johnson | August | 1980-08-31 |
  1031. | Jane | Smith | December | 1987-12-06 |
  1032. | Doug | Brown | December | 1954-12-07 |
  1033. +------------+-----------+----------+------------+
  1034. 10 rows in set (0.00 sec)
  1035. mysql> SELECT p.first_name, h.address FROM people p INNER JOIN homes h on (p.home_id = h.id);
  1036. +------------+----------------------------------------+
  1037. | first_name | address |
  1038. +------------+----------------------------------------+
  1039. | Noelle | 36 E. Bayberry Rd.Savannah, GA 31404 |
  1040. | Thomas | 36 E. Bayberry Rd.Savannah, GA 31404 |
  1041. | Paul | 36 E. Bayberry Rd.Savannah, GA 31404 |
  1042. | Sheeri | 11 Essex Dr.Farmingdale, NY 11735 |
  1043. | Raj | 920 Arlington Street Clifton, NJ 07011 |
  1044. | Jane | 920 Arlington Street Clifton, NJ 07011 |
  1045. | Doug | 920 Arlington Street Clifton, NJ 07011 |
  1046. | John | 234 High Street, PA 19159 |
  1047. +------------+----------------------------------------+
  1048. 8 rows in set (0.00 sec)
  1049. >