Hi everyone
This is just a quick question. i have incorrectly drafted my SQL query and would really appreciate advice on why i missed the mark.
Below is a query to determine how many times a user has logged into a member login section. the query was incorrectly drafted because it returns zero results.
However, just below the incorrect mySQL query is the same query that was tested in MYSQL: this query returns the correct results. So, i obviously ran into problems when i tried to integrate the query into a search function.
THE QUERY
The MYQL query that works
THE TABLE
Thank you very much for your kind assistance
warmest regards
Andreea
This is just a quick question. i have incorrectly drafted my SQL query and would really appreciate advice on why i missed the mark.
Below is a query to determine how many times a user has logged into a member login section. the query was incorrectly drafted because it returns zero results.
However, just below the incorrect mySQL query is the same query that was tested in MYSQL: this query returns the correct results. So, i obviously ran into problems when i tried to integrate the query into a search function.
THE QUERY
PHP Code:
SELECT
u.user_id,
log. num_loggins,
log.time_loggin,
log.seconds_loggin
FROM
users u
LEFT OUTER JOIN
( SELECT log.user_id,
COUNT(*)num_loggins,
FROM_UNIXTIME( MAX(log.logindate), '%D %b %Y' ) AS time_loggin,
FROM_UNIXTIME( MAX(log.logindate), '%r' ) AS seconds_loggin
FROM logindate log
) AS log
ON log.user_id = u.user_id
PHP Code:
SELECT log.user_id,
COUNT(*)num_loggins,
FROM_UNIXTIME( MAX(log.logindate), '%D %b %Y' ) AS time_loggin,
FROM_UNIXTIME( MAX(log.logindate), '%r' ) AS seconds_loggin
FROM logindate log
where log.user_id = 115
THE TABLE
PHP Code:
CREATE TABLE users(
user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
membership_type CHAR(3) NOT NULL,
PRIMARY KEY (user_id)
}
CREATE TABLE logindate(
user_id MEDIUMINT UNSIGNED NOT NULL,
logindate VARCHAR(30) NOT NULL,
url VARCHAR(30) NOT NULL,
location VARCHAR(30) NOT NULL,
INDEX login (user_id, logindate)
);
Thank you very much for your kind assistance
warmest regards
Andreea