php - SQL Query matching two fields -


i have table called cc_site, in table store results of pings different ip addresses.

the table has 4 fields:

  • auto increment id field
  • date (which includes time)
  • ip address
  • status (used determine if ping successful or not).

i'm trying create query give me latest result based off date field individual ip address. code i'm using below doesn't work unless ip i'm using in query latest entry in table.

$query = "select *           cc_site           ip='$host'           , date in (               select max(date)               cc_site           )"; 

i knew query incorrect have not been able find code perform query need.

any great.

no need of sub-query. use can use order , limit instead -

select * cc_site ip='$host' order `date` desc limit 1 

this sort records in descending order according date , return record highest record.


Comments