Using table alias to qualify column name : Simple JOIN « Join « SQL / MySQL






Using table alias to qualify column name

        
mysql>
mysql>
mysql>
mysql> CREATE   TABLE TEAMS
    ->         (TEAMNO         INTEGER      NOT NULL,
    ->          EmployeeNO       INTEGER      NOT NULL,
    ->          DIVISION       CHAR(6)      NOT NULL,
    ->          PRIMARY KEY    (TEAMNO)             );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql> INSERT INTO TEAMS VALUES (1,  6, 'first');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO TEAMS VALUES (2, 27, 'second');
Query OK, 1 row affected (0.00 sec)

mysql>
mysql>
mysql> CREATE   TABLE PENALTIES
    ->         (PAYMENTNO      INTEGER      NOT NULL,
    ->          EmployeeNO       INTEGER      NOT NULL,
    ->          PAYMENT_DATE   DATE         NOT NULL,
    ->          AMOUNT         DECIMAL(7,2) NOT NULL,
    ->          PRIMARY KEY    (PAYMENTNO)          );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> INSERT INTO PENALTIES VALUES (1,  6, '1980-12-08',100);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (2, 44, '1981-05-05', 75);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (3, 27, '1983-09-10',100);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (4,104, '1984-12-08', 50);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (5, 44, '1980-12-08', 25);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (6,  8, '1980-12-08', 25);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (7, 44, '1982-12-30', 30);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (8, 27, '1984-11-12', 75);
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> SELECT   T.EmployeeNO
    -> FROM     TEAMS AS T, PENALTIES AS PEN
    -> WHERE    T.EmployeeNO = PEN.EmployeeNO;
+------------+
| EmployeeNO |
+------------+
|          6 |
|         27 |
|         27 |
+------------+
3 rows in set (0.00 sec)

mysql>
mysql>
mysql> drop table teams;
Query OK, 0 rows affected (0.00 sec)

mysql> drop table PENALTIES;
Query OK, 0 rows affected (0.00 sec)

mysql>

   
    
    
    
    
    
    
    
  








Related examples in the same category

1.Using More Than one Table
2.Self join
3.Simple table join
4.Join three tables
5.Query data from two tables
6.JOIN two tables with alias name
7.Using a Join to Control Query Output Order
8.Using a Join to Create a Lookup Table from Descriptive Labels
9.Return the first names and surnames of both the sales rep and the customer, as well as the value of the sale
10.Query data from two tables 2
11.Finding Rows in One Table That Match Rows in Another
12.Identify records from author table that corresponds to the author name, use its a_id value to find matching re
13.Using information in the book table to find information in the author table
14.Finding Rows with No Match in Another Table
15.Shorten the output column list to include only columns from the author table
16.List each author from the author table, and whether or not you have any books by the author
17.Using table alias to qualify column name when column names exist
18.PSEUDONYMS FOR TABLE NAMES
19.Qualify the column name with table name