The databas estructure:
mysql> describe user;
+------------------------+-------------+------+-----+---------+-------------
---+
| Field | Type | Null | Key | Default | Extra
|
+------------------------+-------------+------+-----+---------+-------------
---+
| userID | int(11) | NO | PRI | NULL |
auto_increment |
| userName | varchar(20) | YES | | NULL |
|
| userCodeDrivingLicense | varchar(20) | YES | | NULL |
|
+------------------------+-------------+------+-----+---------+-------------
---+
3 rows in set (0.00 sec)
mysql> describe client;
+--------------------------+-------------+------+-----+---------+-----------
-----+
| Field | Type | Null | Key | Default | Extra
|
+--------------------------+-------------+------+-----+---------+-----------
-----+
| clientID | int(11) | NO | PRI | NULL |
auto_increment |
| clientName | varchar(20) | YES | | NULL |
|
| clientCodeDrivingLicense | varchar(20) | YES | | NULL |
|
+--------------------------+-------------+------+-----+---------+-----------
-----+
3 rows in set (0.00 sec)
Rocío Gómez Escribano
<mailto:r.sanchez@stripped> r.gomez@stripped
Descripción: cid:image002.jpg@stripped
Polígono Campollano C/F, nº21T
02007 Albacete (España)
Tlf:967-504-513 Fax: 967-504-513
www.ingenia-soluciones.com
De: Rocio Gomez Escribano [mailto:r.gomez@stripped]
Enviado el: martes, 03 de mayo de 2011 8:09
Para: mysql@stripped
Asunto: independent tables
Everyone has his/her own driving license, and I need to know what kind of
person (client or user) is.
mysql> select userID, clientID from client, user where
(clientCodeDrivingLicense= 321321321 || userCodeDrivingLicense = 321321321);
+--------+-------+
| userID | clientID |
+--------+-------+
| 1 | 2 |
| 2 | 2 |
| 3 | 2 |
| 4 | 2 |
| 5 | 2 |
+--------+-------+
5 rows in set (0.00 sec)
But, what I want is something like that:
+--------+-------+
| userID | clientID |
+--------+-------+
| Null | 2 |
+--------+-------+
I tried something like this:
select COUNT(DISTINCT u.userID), userID, clientID from client, user where
(clientCodeDrivingLicense = 321321321 || userCodeDrivingLicense =
321321321);
+--------------------------+--------+-------+
| COUNT(DISTINCT u.userID) | userID | clientID |
+--------------------------+--------+-------+
| 5 | 1 | 2 |
+--------------------------+--------+-------+
1 row in set (0.00 sec)
But it wont be efficient enough in the future.
I suppose my solution is an Join, but they have no intersection, so, I cant
imagine how do it
Thank you!!
Regards
Rocío Gómez Escribano
<mailto:r.sanchez@stripped> r.gomez@stripped
Descripción: cid:image002.jpg@stripped
Polígono Campollano C/F, nº21T
02007 Albacete (España)
Tlf:967-504-513 Fax: 967-504-513
www.ingenia-soluciones.com
Attachment: [text/html]
Attachment: [text/html]
Attachment: [text/html]