[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

PHP MS SQL using TOP

Posted on 2004-10-22
4
Medium Priority
?
257 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
Comment
Question by:netele
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 8

Expert Comment

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

Author Comment

by:netele
ID: 12386821
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:
sigmacon earned 1500 total points
ID: 12386906
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
ID: 12387357
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

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

650 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