Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
C:\Users\user>CD..
C:\Users>CD..
C:\>CD xampp/mysql/bin
C:\xampp\mysql\bin>mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.1.31-MariaDB mariadb.org binary distribution
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [basisdata]> CREATE TABLE consultant (CID VARCHAR (5), CName VARCHAR (10
), Stat VARCHAR (3), SID INT);
Query OK, 0 rows affected (0.27 sec)
MariaDB [basisdata]> SELECT a.SID, a.Name, a.Age, a.GPA, b.CID, b.CName, b.Stat
FROM students a JOIN consultant b ON a.SID=b.SID;
+-------+-------+------+------+------+--------+------+
| SID | Name | Age | GPA | CID | CName | Stat |
+-------+-------+------+------+------+--------+------+
| 53666 | Jones | 18 | 3.40 | C001 | James | C1 |
| 53666 | Jones | 18 | 3.40 | C003 | Brown | C2 |
| 53668 | Smith | 18 | 3.20 | C002 | Schole | C1 |
| 53668 | Smith | 18 | 3.20 | C005 | Murphy | C2 |
+-------+-------+------+------+------+--------+------+
4 rows in set (0.01 sec)
MariaDB [basisdata]> SELECT a.SID, a.Name, a.Age, a.GPA, b.CID, b.CName, b.Stat
FROM students a LEFT JOIN consultant b ON a.SID=b.SID;
+-------+---------+------+------+------+--------+------+
| SID | Name | Age | GPA | CID | CName | Stat |
+-------+---------+------+------+------+--------+------+
| 53666 | Jones | 18 | 3.40 | C001 | James | C1 |
| 53668 | Smith | 18 | 3.20 | C002 | Schole | C1 |
| 53666 | Jones | 18 | 3.40 | C003 | Brown | C2 |
| 53668 | Smith | 18 | 3.20 | C005 | Murphy | C2 |
| 53669 | Melissa | 17 | 2.75 | NULL | NULL | NULL |
| 53670 | Hilden | 19 | 2.89 | NULL | NULL | NULL |
+-------+---------+------+------+------+--------+------+
6 rows in set (0.01 sec)
MariaDB [basisdata]> SELECT a.SID, a.Name, a.Age, a.GPA, b.CID, b.CName, b.Stat
FROM students a RIGHT JOIN consultant b ON a.SID=b.SID;
+-------+-------+------+------+------+--------+------+
| SID | Name | Age | GPA | CID | CName | Stat |
+-------+-------+------+------+------+--------+------+
| 53666 | Jones | 18 | 3.40 | C001 | James | C1 |
| 53668 | Smith | 18 | 3.20 | C002 | Schole | C1 |
| 53666 | Jones | 18 | 3.40 | C003 | Brown | C2 |
| 53668 | Smith | 18 | 3.20 | C005 | Murphy | C2 |
| NULL | NULL | NULL | NULL | C006 | Andre | C2 |
| NULL | NULL | NULL | NULL | C007 | Jenny | C1 |
+-------+-------+------+------+------+--------+------+
6 rows in set (0.00 sec)
MariaDB [basisdata]>
a = students
b = consultant