I have this table definition:
table_1
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| id | int(15) | | PRI | NULL | auto_increment |
| Contrato | int(11) | | MUL | 0 | |
| UserName | varchar(30) | | MUL | | |
+----------+-------------+------+-----+---------+----------------+
table_2
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| id | int(11) | | PRI | NULL | auto_increment |
| Contrato | int(11) | | | 0 | |
| Nombre | varchar(50) | | | | |
| UserName | varchar(15) | | MUL | | |
+----------+-------------+------+-----+---------+----------------+
table_3
+---------------------+--------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra
| |
+---------------------+--------------+------+-----+---------------------+----------------+
| id | bigint(21) | | PRI | NULL | auto_increment |
| UserName | varchar(32) | | MUL | |
| |
| Saldo | float | | | |
| |
+---------------------+--------------+------+-----+---------------------+----------------+
I need to retrieve the column Saldo from table 3 for each Contrato (could in table 1
and table 2), so i executed this select...
SELECT Contrato, Saldo FROM table_3, table_2, table_1 WHERE (table_1.UserName =
table_3.UserName) OR (table_2.UserName = table_3.UserName)
This select return an error that Contrato is ambiguous.
I can not do 2 queries, so the only solution to this is an UNION, but MySQL does not
support them yet..
Can someone help me?