Hi all,
I know how to do this query with subqueries like this:

select * from traf_oper where
  rutasalien in
  (select ruta_salid from rutas where codigo_ope = 0)
  and
  rutaentran in
  (select ruta_salid from rutas where codigo_ope > 0)

--------------------------------------------------------------

The table structures is like this:

mysql> explain traf_oper;
+------------+----------+------+-----+---------+-------+
| Field      | Type     | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+-------+
| tel        | char(8)  | YES  | MUL | NULL    |       |
| fecha      | char(8)  | YES  |     | NULL    |       |
| hora       | char(6)  | YES  |     | NULL    |       |
| telefb     | char(14) | YES  |     | NULL    |       |
| tiempotasa | char(6)  | YES  |     | NULL    |       |
| rutasalien | char(7)  | YES  |     | NULL    |       |
| rutaentran | char(7)  | YES  |     | NULL    |       |
| serie      | char(3)  | YES  |     | NULL    |       |
| tipotraf   | int(1)   | YES  |     | NULL    |       |
| minutos    | int(4)   | YES  |     | NULL    |       |
+------------+----------+------+-----+---------+-------+
10 rows in set (0.44 sec)

mysql> explain rutas;
+------------+----------+------+-----+---------+-------+
| Field      | Type     | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+-------+
| CODIGO_TRA | int(6)   | YES  |     | NULL    |       |
| RUTA_SALID | char(20) | YES  | MUL | NULL    |       |
| DESCRIPCIO | char(20) | YES  |     | NULL    |       |
| CODIGO_CIR | int(6)   | YES  |     | NULL    |       |
| TIPO_RUTA  | char(20) | YES  |     | NULL    |       |
| SISTEMA_TA | int(6)   | YES  |     | NULL    |       |
| CODIGO_OPE | int(6)   | YES  |     | NULL    |       |
| CORRELATIV | int(6)   | YES  |     | NULL    |       |
+------------+----------+------+-----+---------+-------+
8 rows in set (0.08 sec)

--------------------------------------------------------------

I tried to do this:

mysql> explain select a.* from traf_oper a join rutas b on a.rutasalien = b.ruta_salid where b.codigo_ope = 0 and
a.rutaentran = b.ruta_salid where b.codigo_ope > 0;
ERROR 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version
for the right syntax to use near 'where b.codigo_ope > 0' at line 1


How can I substitute multiple subqueries with JOIN's?
Thanks in advance.



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to