domagoj
-
Posts
7 -
Joined
-
Last visited
Never
Posts posted by domagoj
-
-
Hi,
select * from table where date_format(mytime) = date_format(max(mytime)) ?? Is this only possible with temporary tables?
P.
This does not work, that\'s why I\'m posting to this forum
And I didn\'t understand the thing with 3 queries - you thought that I should use
$result = mysql_query($query, $link) three times or just once?
Because I was thinking that this should work if I executed just once the whole \"stored procedure\"
-
it doesn\'t work in where clause, don\'t ask why, I don\'t know. With MSAccess and MSSQL it works, but MySQL doesn\'t support subqueries yet.
-
That is sort of what I meant indeed, but I dont know if mysql gonna have that. Just do the extraction in PHP and save the results in variables you can use for the second query...
it works fine inside the mysql, but the answer is here:
$query = " DROP TABLE IF EXISTS tmp_table; CREATE TEMPORARY TABLE tmp_table (mjgod VARCHAR(20)) TYPE=HEAP; INSERT INTO tmp_table SELECT DATE_FORMAT(max(time), \'%M, %Y\') FROM clanci; SELECT clanci.*, tmp_table.* as najnoviji from clanci, tmp_table WHERE DATE_FORMAT(clanci.time,\'%M, %Y\')=tmp_table.mjgod; "; $result = mysql_query($query, $link) or die("No results for bulletin.");
The only problem is that this code works inside mysql prompt, but when I try to execute multiple SQL statement string (above) from PHP it returns no results.
Does anybody know is it possible to execute some kind of SQL procedure like above one from PHP?
-
maybe something like this:
select * from ids where extract(month from time) = extract(month from current_date) and extract(year from time) = extract(year from current_date);
-
you should use date_format(mytime, \"format\")
See documentation for the date_format function in mysql.
Then use
select * form table where date_format(...) = \'03\';
\'03\' is march (should be obvious).
P.
That\'s OK but \'03\' is not a constant, so i need to make a subquery which MySQL doesn\'t support. I think the beginning of the SQL code should be (maybe ) something like this:
DROP TABLE IF EXISTS tmp_table;
CREATE TEMPORARY TABLE tmp_table (mjgod VARCHAR(20)) TYPE=HEAP;
INSERT INTO tmp_table SELECT DATE_FORMAT(max(time), \'%M, %Y\') FROM clanci;
The second thing - did someone try to store several QUERIES in one PHP string and then execute? I\'ve got no results from database.
-
I have a table with datetime column in MySQL database. If I wanted to select all rows with the newest month how I would do it?
For example, table ids:
+----+---------------------+
| id | mytime |
+----+---------------------+
| 1 | 2003-03-01 21:03:34 |
| 2 | 2003-01-01 20:33:34 |
| 3 | 2003-01-01 21:03:34 |
| 4 | 2003-03-01 02:03:34 |
| 5 | 2002-03-01 15:13:34 |
+----+---------------------+
from which I want to select all ids from March 2003.
datestamp and mysql
in MySQL Help
Posted
Thnx, I think this should work.