database - Debugging a SQL Query -


i have table structure below. need select row user_id =100 , user_sub_id = 1 , time_used = minimum of all , timestamp highest. output of query should result in :

us;1365510103204;ny;1365510103;100;1;678; 

my query looks this.

select *  my_table  code='de'    , user_id = 100    , user_sub_id = 1   , time_used = (select min(time_used)                    my_table                    code='de'                      , user_id=100                      , user_sub_id= 1); 

this returns me 4 rows. need 1, 1 highest timestamp. many

code:   timestamp:  location:   time_recorded:  user_id:    user_sub_id:    time_used "us;1365510102420;ny;1365510102;100;1;1078; "us;1365510102719;ny;1365510102;100;1;978; "us;1365510103204;ny;1365510103;100;1;878; "us;1365510102232;ny;1365510102;100;1;678; "us;1365510102420;ny;1365510102;100;1;678; "us;1365510102719;ny;1365510102;100;1;678; "us;1365510103204;ny;1365510103;100;1;678; "us;1365510102420;ny;1365510102;101;1;678; "us;1365510102719;ny;1365510102;101;1;638; "us;1365510103204;ny;1365510103;101;1;638; 

then try this:

select * my_table code='de'   , user_id=100   , user_sub_id=1   , time_used=(     select min(time_used)     my_table     code='de'     , user_id=100 , user_sub_id=1   ) order "timestamp" desc --   <-- adds sorting limit 1; --   <-- retrieves 1 row 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -