PDA

View Full Version : Help with this query


wert
05-26-2003, 05:33 PM
I don't know why this query gives me all the rows in my table Transacciones? does any one know why? here is the query:

//this is my table:
mysql> desc transacciones;
+----------+-------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------------+------+-----+---------+-------+
| Fecha | date | YES | | NULL | |
| Hora | time | YES | | NULL | |
| Monto | bigint(20) | YES | | NULL | |
| Tienda | int(11) | YES | | NULL | |
| Concepto | enum('R','V','D') | YES | | NULL | |
+----------+-------------------+------+-----+---------+-------+
5 rows in set (0.10 sec)
//and this is the query:
select * from transacciones where (fecha <= CURRENT_DATE) and ( fecha >= DATE_SUB(fecha, INTERVAL 3 DAY));
it supose to return only the transactions from three days a go to now, but it gives me all the table's rows, I just don't get it.

Please help!

wert
05-26-2003, 06:12 PM
I got it already:

//Iwas using the same Fecha field for the calculation: so it was like this:
select * from transacciones where (fecha <= CURRENT_DATE) and ( fecha >= DATE_SUB(fecha, INTERVAL 3 DAY));
//and it supose ti be like this ;
select * from transacciones where (fecha <= CURRENT_DATE) and ( fecha >= DATE_SUB(CURRENT_DATE, INTERVAL 3 DAY));


I've just to change Fecha for CUERRENT_DATE, simple right?