SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Limit + Mssql

  1. #1
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Limit + Mssql

    Hi all,

    What is the equivalent of mysql's LIMIT clause for MSSQL Server?

    Thanks.

    PHP Code:
     $find_date mssql_query("select date from date where date = '$value
                     and course_ID = '
    $course'    LIMIT 1"); 

  2. #2
    SitePoint Guru
    Join Date
    Aug 2003
    Location
    CT
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT Top X from table

    keep in mind, MS doesn't support limit X,Y for starting ranges.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,244
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    kev, are you sure this is what you're running in MySQL --
    Code:
    select date 
      from date 
     where date = '$value' 
       and course_ID = '$course' 
    LIMIT 1
    because all this does is determine whether there exists at least one row in the "date" table for the given "date" value and course value -- assuming that there would be more than one (which, the longer i think about it, doesn't make sense)

    you are returning the "date" value but of course you could really return anything, right? i mean, because you already know the "date" value

    so you could do this in SQL Server --
    Code:
    select 'Yep!' 
     where exists
         ( select 937
             from date
            where date = '$value' 
              and course_ID = '$course' )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Rudy,

    I'm using LIMIT to display just one result. So is the above right in what I want to do?

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,244
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    is it right for what you're trying to do?

    that depends on what you're trying to do, which, and please don't take this the wrong way, you haven't communicated very well at all

    is the same course available on the same day more than once?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Code:
    SELECT TOP 1 * 
    FROM table
    ORDER BY field
    The TOP syntax works in any version of SQL Server from 7 on up.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •