List:General Discussion« Previous MessageNext Message »
From:bruce Date:January 5 2007 4:54am
Subject:db/query question...
View as plain text  
hi...

a further test...

the following test tbl/information:
dog
  name	char
  status	int
  _date     timestamp
  id		int

test data
  dog
   name	status	   _date	id
    tom	 1		 01/20/07	1
    tom      2           01/21/07	2
    sue      1           01/20/07	3
    tom      3           01/22/07	4
    sue      2           01/21/07	5
    bob      1           01/20/07	6
    tom      4           01/23/07	7
    sue      3           01/22/07	5
    sue      4           01/23/07	5
    sue      3           01/24/07	5


if i do a regular group, i can get (for tom)
    tom	 1		 01/20/07	1
    tom      2           01/21/07	2
    tom      3           01/22/07	4
    tom      4           01/23/07	7

    sue      1           01/20/07	3
    sue      2           01/21/07	5
    sue      3           01/22/07	5
    sue      4           01/23/07	5
    sue      3           01/24/07	5



here's the tricky part. if i want to get the row with the status=3, but only
if there's not a status=4 that has a later date, how do i accomplish
this...??

so, for tom, i would return 'null', and for sue, i'd return '3' for the
'01/24/07' the date for the last '3' is later than the date for the last
'4'...

i imagine that there's a way to accomplish this using subselects.

any thoughts/comments..

thanks

-bruce








Thread
db/query question...bruce5 Jan
  • Re: db/query question...Shawn Green6 Jan
    • mysql - connections questionbruce10 Jan