mysql> update detalle set valorventa=(select valorunitario+(valorunitario*0.23) from articulo where articulo.codigo=detalle.codigo); Query OK, 7 rows affected (0.05 sec) Rows matched: 7 Changed: 7 Warnings: 0 mysql> select * from detalle; +----+------------+------------+----------+------------+-------+--------+ | id | nrofactura | fecha | cantidad | valorventa | total | codigo | +----+------------+------------+----------+------------+-------+--------+ | 1 | 1200 | 2010-01-30 | 3 | 1168500 | 0 | 150 | | 2 | 1250 | 2010-02-13 | 5 | 1168500 | 0 | 150 | | 3 | 1250 | 2010-02-13 | 7 | 922500 | 0 | 250 | | 4 | 1300 | 2010-03-02 | 1 | 1205400 | 0 | 350 | | 5 | 1300 | 2010-03-02 | 2 | 135300 | 0 | 300 | | 6 | 1400 | 2010-03-11 | 3 | 1476000 | 0 | 200 | | 7 | 1500 | 2010-03-21 | 5 | 922500 | 0 | 250 | +----+------------+------------+----------+------------+-------+--------+ 7 rows in set (0.00 sec) mysql> update detalle set total=cantidad * valor venta; ERROR 1064 (42000): 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 'venta' at line 1 mysql> update detalle set total = cantidad * valor venta; ERROR 1064 (42000): 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 'venta' at line 1 mysql> update detalle set total = cantidad * valorventa; Query OK, 7 rows affected (0.00 sec) Rows matched: 7 Changed: 7 Warnings: 0 mysql> update articulo set existencia=cantidad-(select sum( from detalle where detalle.codigo=articulo.codigo); ERROR 1064 (42000): 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 'from detalle where detalle.codigo=articulo.codigo)' at line 1 mysql> update articulo set existencia=cantidad-(select sum(cantidad) from detalle where detalle.codigo=articulo.codigo);; Query OK, 5 rows affected (0.05 sec) Rows matched: 5 Changed: 5 Warnings: 0 ERROR: No query specified mysql> update articulo set existencia=cantidad-(select sum(cantidad) from detalle where detalle.codigo=articulo.codigo); Query OK, 0 rows affected (0.00 sec) Rows matched: 5 Changed: 0 Warnings: 0 mysql> select * from articulo; +--------+------------+----------+---------------+------------+ | codigo | articulo | cantidad | valorunitario | existencia | +--------+------------+----------+---------------+------------+ | 150 | nevera | 25 | 950000 | 17 | | 200 | televisor | 11 | 1200000 | 8 | | 250 | estufa | 30 | 750000 | 18 | | 300 | ventilador | 17 | 110000 | 15 | | 350 | lavadora | 13 | 980000 | 12 | +--------+------------+----------+---------------+------------+ 5 rows in set (0.00 sec) mysql> delete from articulo where codigo=(select codigo from detalle where cantidad between 3 and 5 and detalle.codigo=articulo.codigo group by articulo.codigo); Query OK, 3 rows affected (0.22 sec) mysql> select * from articulo; +--------+------------+----------+---------------+------------+ | codigo | articulo | cantidad | valorunitario | existencia | +--------+------------+----------+---------------+------------+ | 300 | ventilador | 17 | 110000 | 15 | | 350 | lavadora | 13 | 980000 | 12 | +--------+------------+----------+---------------+------------+ 2 rows in set (0.00 sec) mysql> mysql> mysql> create table detallecopia like detalle; Query OK, 0 rows affected (0.67 sec) mysql> describe detallecopia; +------------+----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+----------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | nrofactura | char(10) | NO | | NULL | | | fecha | date | NO | | NULL | | | cantidad | int(11) | NO | | NULL | | | valorventa | int(11) | NO | | NULL | | | total | int(11) | NO | | NULL | | | codigo | char(10) | NO | | NULL | | +------------+----------+------+-----+---------+----------------+ 7 rows in set (0.28 sec) mysql> show tables; +------------------------+ | Tables_in_subconsultas | +------------------------+ | articulo | | detalle | | detallecopia | +------------------------+ 3 rows in set (0.06 sec) mysql> select * from detallecopia; Empty set (0.02 sec) mysql> insert into detallecopia select * from detalle where month (fecha)=2; Query OK, 2 rows affected (0.03 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> show tables; +------------------------+ | Tables_in_subconsultas | +------------------------+ | articulo | | detalle | | detallecopia | +------------------------+ 3 rows in set (0.00 sec) mysql> describe detallecopia; +------------+----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+----------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | nrofactura | char(10) | NO | | NULL | | | fecha | date | NO | | NULL | | | cantidad | int(11) | NO | | NULL | | | valorventa | int(11) | NO | | NULL | | | total | int(11) | NO | | NULL | | | codigo | char(10) | NO | | NULL | | +------------+----------+------+-----+---------+----------------+ 7 rows in set (0.06 sec) mysql> exit