Posted on 2004-10-22
Last Modified: 2006-11-17

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...

Question by:netele
    LVL 8

    Expert Comment

    Please provide the complete query, and an example of the data you are querying.

    Author Comment

    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";


    LVL 8

    Accepted Solution

    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.

    Author Comment

    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!


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    The viewer will learn how to count occurrences of each item in an array.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    933 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now