• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

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.
0
netele
Asked:
netele
  • 2
  • 2
1 Solution
 
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
 
sigmaconCommented:
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now