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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
mysql> select * from employees,titles where employees.emp_no = titles.emp_no limit 5; + | emp_no | birth_date | first_name | last_name | gender | hire_date | emp_no | title | from_date | to_date | + | 10001 | 1953-09-02 | Georgi | Facello | M | 1986-06-26 | 10001 | Senior Engineer | 1986-06-26 | 9999-01-01 | | 10002 | 1964-06-02 | Bezalel | Simmel | F | 1985-11-21 | 10002 | Staff | 1996-08-03 | 9999-01-01 | | 10003 | 1959-12-03 | Parto | Bamford | M | 1986-08-28 | 10003 | Senior Engineer | 1995-12-03 | 9999-01-01 | | 10004 | 1954-05-01 | Chirstian | Koblick | M | 1986-12-01 | 10004 | Engineer | 1986-12-01 | 1995-12-01 | | 10004 | 1954-05-01 | Chirstian | Koblick | M | 1986-12-01 | 10004 | Senior Engineer | 1995-12-01 | 9999-01-01 | + 5 rows in set (0.00 sec)
mysql> select emp_no, concat(last_name,' ', first_name), gender, title -> from employees,titles -> where employees.emp_no = titles.emp_no limit 5; ERROR 1052 (23000): Column 'emp_no' in field list is ambiguous
mysql> select employees.emp_no, -- 指定了employees -> concat(last_name,' ', first_name), gender, title -> from employees,titles -> where employees.emp_no = titles.emp_no limit 5; + | emp_no | concat(last_name,' ', first_name) | gender | title | + | 10001 | Facello Georgi | M | Senior Engineer | | 10002 | Simmel Bezalel | F | Staff | | 10003 | Bamford Parto | M | Senior Engineer | | 10004 | Koblick Chirstian | M | Engineer | | 10004 | Koblick Chirstian | M | Senior Engineer | +
mysql> select employees.emp_no, -> concat(last_name,' ', first_name) as emp_name, gender, title -- 对名字的列取一个别名叫emp_name -> from employees,titles -> where employees.emp_no = titles.emp_no limit 5; + | emp_no | emp_name | gender | title | + | 10001 | Facello Georgi | M | Senior Engineer | | 10002 | Simmel Bezalel | F | Staff | | 10003 | Bamford Parto | M | Senior Engineer | | 10004 | Koblick Chirstian | M | Engineer | | 10004 | Koblick Chirstian | M | Senior Engineer | + 5 rows in set (0.00 sec)
mysql> select e.emp_no, -> concat(last_name,' ', first_name) as emp_name, gender, title -> from employees as e,titles as t -> where e.emp_no = t.emp_no limit 5; + | emp_no | emp_name | gender | title | + | 10001 | Facello Georgi | M | Senior Engineer | | 10002 | Simmel Bezalel | F | Staff | | 10003 | Bamford Parto | M | Senior Engineer | | 10004 | Koblick Chirstian | M | Engineer | | 10004 | Koblick Chirstian | M | Senior Engineer | + 5 rows in set (0.00 sec)
mysql> select e.emp_no, -> concat(last_name,' ', first_name) as emp_name, gender, title -> from employees as e inner join titles as t -> on e.emp_no = t.emp_no limit 5; + | emp_no | emp_name | gender | title | + | 10001 | Facello Georgi | M | Senior Engineer | | 10002 | Simmel Bezalel | F | Staff | | 10003 | Bamford Parto | M | Senior Engineer | | 10004 | Koblick Chirstian | M | Engineer | | 10004 | Koblick Chirstian | M | Senior Engineer | + 5 rows in set (0.00 sec)
mysql> explain select e.emp_no, -> concat(last_name,' ', first_name) as emp_name, gender, title -> from employees as e,titles as t -> where e.emp_no = t.emp_no limit 5; + | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | + | 1 | SIMPLE | e | NULL | ALL | PRIMARY | NULL | NULL | NULL | 298124 | 100.00 | NULL | | 1 | SIMPLE | t | NULL | ref | PRIMARY | PRIMARY | 4 | employees.e.emp_no | 1 | 100.00 | Using index | + 2 rows in set, 1 warning (0.00 sec)
mysql> explain select e.emp_no, -> concat(last_name,' ', first_name) as emp_name, gender, title -> from employees as e inner join titles as t -> on e.emp_no = t.emp_no limit 5; + | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | + | 1 | SIMPLE | e | NULL | ALL | PRIMARY | NULL | NULL | NULL | 298124 | 100.00 | NULL | | 1 | SIMPLE | t | NULL | ref | PRIMARY | PRIMARY | 4 | employees.e.emp_no | 1 | 100.00 | Using index | + 2 rows in set, 1 warning (0.00 sec)
|