PHP MS SQL using TOP

Hi,

I have a the following,

$sql = "SELECT TOP 3 id, title, etc, etc"

If I remove the "TOP 3" I get 4 records returned. When I use the "TOP 3" I get only 2 records!

I can't understand what's going on...

Thanks.
neteleAsked:
Who is Participating?
 
sigmaconConnect With a Mentor Commented:
OK, since I don't know the data, I can only make assumptions: Have you tested this query in Query Analyzer to make sure that it is actually the query that is behaving funny? Since this is embedded in PHP script, how are you actually counting the rows / and or painting the result? Please also provide some sample data. From the query itself it cannot be derived whether there is anything wrong. The query looks fine to me an should work.
0
 
sigmaconCommented:
Please provide the complete query, and an example of the data you are querying.
0
 
neteleAuthor Commented:
This is what I got,

                Select TOP 3 id,title,
      pubTime,startDate,arcDate, applicationID,
      pubTime + startdate as startDayTime
      from PressReleases
      where ((arcDate >= '$dtstr') OR (arcDate = NULL))
      AND (IsActive = 1)
      AND (applicationID = $appID)
      order by enteredDate DESC";

Thanks

0
 
neteleAuthor Commented:
Thanks, I figured out the problem. I had a loop that wan't working the way it should... The end of a very long day...

You get the points for effort!

Thanks
0
All Courses

From novice to tech pro — start learning today.