Jump to content

[SOLVED] Select Top 1* returns multiple results!


wellscam

Recommended Posts

Hey,

 

I'm querying an Access database using PHP with this query to return the last entry in the database and display how current it is.

 

$query = odbc_exec($odbc, "SELECT Top 1 * FROM AllInfo WHERE IO = 'Out' AND CO = '51' ORDER BY [DateTime] DESC") or die (odbc_errormsg()); 
while($row = odbc_fetch_array($query)) 
{ 
    echo 'Database current as of<strong> '.date("F j, Y, g:i a", strtotime($row['DateTime'])).'</strong> and will update every 23 minutes.'; 
} 

 

The problem is, if there are 2 or 3 identical records in there, it will return all of those records. How do I tell it to only return the first one? Or maybe add a second order by parameter?

When I try this,

$query = odbc_exec($odbc, "SELECT Top 1 * FROM AllInfo WHERE IO = 'Out' AND CO = '51' ORDER BY [DateTime, Extension] DESC") or die (odbc_errormsg()); 

 

I get this error:

[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

 

I understand that there shouldn't be identical rows. Unfortunately, the database is being generated by a software program that I have no control over and it does not add a unique id for each row. It's a phone program that queries and logs our switch data into an Access database with simple data like Extension, Time, Date, Line Used, Incoming/Outgoing, Total Duration etc...

 

My result sometimes repeats a couple of times and I'm thinking that it's because there are multiple calls with the same timestamp, is there another reason my query would produce the result twice?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.