Solved

PHP MS SQL using TOP

Posted on 2004-10-22
210 Views
Last Modified: 2006-11-17
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
Question by:netele
    4 Comments
     
    LVL 8

    Expert Comment

    by:sigmacon
    Please provide the complete query, and an example of the data you are querying.
    0
     

    Author Comment

    by:netele
    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
     
    LVL 8

    Accepted Solution

    by:
    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
     

    Author Comment

    by:netele
    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

    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