1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

LIMIT Query

Discussion in 'Databases' started by Weirfire, Nov 2, 2005.

  1. #1
    I would like to SELECT all values in a table starting at the 2nd result!

    Anyone know a solution to this without doing a query like

    SELECT X FROM Y LIMIT 2,47358927354

    ???
     
    Weirfire, Nov 2, 2005 IP
  2. heapseo

    heapseo Peon

    Messages:
    636
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    can u not just select them all and filter out the first result using php or whatever?
     
    heapseo, Nov 2, 2005 IP
    Weirfire likes this.
  3. fooey

    fooey Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    here's an example for a different vendor with coldfusion sprinkled in, but you should get the idea, and I didn't feel like cleaning it up ;p

    SELECT
    	an_id,
    	as_ShortName,
    	ac_name,
    	an_date,
    	an_link,
    	an_title,
    	an_description,
    	an_remote_id,
    	an_hasCache AS isCached
    FROM (	SELECT TOP #PerPage# * FROM (
    			SELECT TOP #Evaluate(PerPage * PageNum)# MIN(an_id) AS MinID
    			FROM Archives_News
    				 LEFT JOIN Archives_Sites ON as_id = an_as_id
    				 LEFT JOIN Archives_Categories ON ac_id = an_ac_id
    			GROUP BY an_as_id, an_title, an_remote_id
    			ORDER BY MIN(an_id) DESC
    			) inner1
    		ORDER BY MinID
    		) inner2
    	INNER JOIN Archives_News ON MinID = an_id
    	 LEFT JOIN Archives_Sites ON as_id = an_as_id
    	 LEFT JOIN Archives_Categories ON ac_id = an_ac_id
    ORDER BY an_id DESC
    Code (markup):
     
    fooey, Nov 2, 2005 IP
  4. nevetS

    nevetS Evolving Dragon

    Messages:
    2,544
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    135
    #4
    tiptopvillas is right. You need to parse out that record in your php script. The LIMIT clause allows you to set an offset value, but there is no way (that I know of) to use the LIMIT clause without limiting the rows returned.

    Either that, or use your first solution and put a crazy high number in your rowcount parameter.
     
    nevetS, Nov 2, 2005 IP
    Weirfire likes this.
  5. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #5
    Thanks guys. Just thought there might be an operator for the LIMIT command that could be used to select everything after a certain point.
     
    Weirfire, Nov 2, 2005 IP
  6. JoeO

    JoeO Peon

    Messages:
    431
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Does this one record always change? or is there an ID you can use to exclude it?
     
    JoeO, Nov 2, 2005 IP
  7. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #7
    Nah the one I'm exluding is the newest 1 which will always be changing. The reason I'm excluding it is because it gets displayed at the top of the page.
     
    Weirfire, Nov 2, 2005 IP
  8. dct

    dct Finder of cool gadgets

    Messages:
    3,132
    Likes Received:
    328
    Best Answers:
    0
    Trophy Points:
    230
    #8
    Just do
    
    select * from abigtablewithacrapfirstrecord
    limit 1, -1
    
    Code (sql):
    :D
     
    dct, Nov 2, 2005 IP
    JoeO and Weirfire like this.
  9. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #9
    All I can say is well done dct :D {clap clap clap}
     
    Weirfire, Nov 2, 2005 IP
  10. JoeO

    JoeO Peon

    Messages:
    431
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #10
    nice one, doesn't seem logical, but who can argue with results? ;)
     
    JoeO, Nov 2, 2005 IP