Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Help with my mySQL query

$
0
0
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
PHP Code:


SELECT 
                 u
.user_id,
                   
lognum_loggins,
          
log.time_loggin,
          
log.seconds_loggin
            
                      
                  
       FROM 
                          users u  


 LEFT OUTER  JOIN 
                
SELECT log.user_id,
                 
COUNT(*)num_loggins,
           
FROM_UNIXTIMEMAX(log.logindate), '%D %b %Y' ) AS time_loggin,
          
FROM_UNIXTIMEMAX(log.logindate), '%r' ) AS seconds_loggin
           FROM  logindate log
                
) AS log
                ON log
.user_id u.user_id 

The MYQL query that works


PHP Code:


     SELECT log
.user_id,
              
COUNT(*)num_loggins,
              
FROM_UNIXTIMEMAX(log.logindate), '%D %b %Y' ) AS time_loggin,
             
FROM_UNIXTIMEMAX(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(3NOT NULL

PRIMARY KEY (user_id)




CREATE TABLE logindate(
user_id MEDIUMINT UNSIGNED NOT NULL
logindate VARCHAR(30NOT NULL,
url VARCHAR(30NOT NULL,
location VARCHAR(30NOT NULL,
INDEX login (user_idlogindate


); 


Thank you very much for your kind assistance

warmest regards

Andreea

Viewing all articles
Browse latest Browse all 13329

Trending Articles