Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2011
    Posts
    16
    Thanks
    1
    Thanked 1 Time in 1 Post

    SQL Limit start from

    I have this query

    Code:
    SELECT * FROM Posts WHERE User = 'admin' ORDER BY Number DESC limit 0,25
    Which would would the following results

    Code:
    2hnsk6i2iqgoh0c6kdbyd	admin	coecxrj0vqkow46h6243v	17:28	2013/01/02	1357147682
    2hnsk6i2iqgoh0c6kdbyd	admin	uvde2od4fffjyri2se3v6	17:28	2013/01/02	1357147682
    2hnsk6i2iqgoh0c6kdbyd	admin	7nvk4tamdcmmqxc8xxzns	17:28	2013/01/02	1357147682
    2hnsk6i2iqgoh0c6kdbyd	admin	46ibv785bpbcqin5csgqt	17:28	2013/01/02	1357147681
    2hnsk6i2iqgoh0c6kdbyd	admin	nprsukm2v7adx62psizcn	17:28	2013/01/02	1357147681
    2hnsk6i2iqgoh0c6kdbyd	admin	5jffjmcrywv28ypxf88m8	17:28	2013/01/02	1357147681
    2hnsk6i2iqgoh0c6kdbyd	admin	i5ejx2hqf7m6m4ybc0b43	17:28	2013/01/02	1357147680
    2hnsk6i2iqgoh0c6kdbyd	admin	m72qzizi0ru4z6e2vz6vq	17:28	2013/01/02	1357147680
    2hnsk6i2iqgoh0c6kdbyd	admin	3mf83zzvow6wt2gfhb6ub	17:28	2013/01/02	1357147680
    2hnsk6i2iqgoh0c6kdbyd	admin	ct2j2u8xx8ny8x3u27sjc	17:27	2013/01/02	1357147679
    2hnsk6i2iqgoh0c6kdbyd	admin	sdbx6iyburbeg0ie0magt	17:27	2013/01/02	1357147679
    2hnsk6i2iqgoh0c6kdbyd	admin	5hir63ok3kq06g3upqbhk	17:27	2013/01/02	1357147679
    2hnsk6i2iqgoh0c6kdbyd	admin	4pvuwgqazd84yck7adoxa	17:27	2013/01/02	1357147678
    2hnsk6i2iqgoh0c6kdbyd	admin	oiv6quuyrpwe8bgirjr4i	17:27	2013/01/02	1357147678
    2hnsk6i2iqgoh0c6kdbyd	admin	xcutah6426zesq323gfwx	17:27	2013/01/02	1357147678
    2hnsk6i2iqgoh0c6kdbyd	admin	hgfqab040h4k55bjedpkt	17:27	2013/01/02	1357147678
    2hnsk6i2iqgoh0c6kdbyd	admin	oonp5r3np5knm5d4ohm55	17:27	2013/01/02	1357147677
    2hnsk6i2iqgoh0c6kdbyd	admin	cbckqm8qi2oaimir2epzi	17:27	2013/01/02	1357147677
    2hnsk6i2iqgoh0c6kdbyd	admin	vtsaqex6wfdmh8ioceuvn	17:27	2013/01/02	1357147677
    2hnsk6i2iqgoh0c6kdbyd	admin	0ubs8ur2wo55ohfuipdo0	17:27	2013/01/02	1357147677
    2hnsk6i2iqgoh0c6kdbyd	admin	8tvorn65epoaict0fp26z	17:27	2013/01/02	1357147676
    2hnsk6i2iqgoh0c6kdbyd	admin	soctqr26i7aycza2u73pi	17:27	2013/01/02	1357147676
    2hnsk6i2iqgoh0c6kdbyd	admin	8ukjwmao2qtt374g6p7ej	17:27	2013/01/02	1357147676
    2hnsk6i2iqgoh0c6kdbyd	admin	4wyinun2ki45h6ww73qg6	17:27	2013/01/02	1357147675
    2hnsk6i2iqgoh0c6kdbyd	admin	3dpsbg2t7s7fj2hbiyenk	17:27	2013/01/02	1357147675
    That brings up forums posts in a topic, but say the user is looking through post history, and wants to use that to go to the topic, i want some code like

    Code:
    SELECT * FROM Posts WHERE User = 'admin' ORDER BY Number DESC limit (SELECT * FROM POSTS WHERE POST = 'soctqr26i7aycza2u73pi'),25.
    That of course doesn't work, but i don't know if you could, and if so, how i would be able to get that piece of code to work

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,200
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    Code:
    SELECT * FROM Posts 
    WHERE User = 'admin' 
    AND Number >= ( SELECT Number FROM POSTS WHERE POST = 'soctqr26i7aycza2u73pi')
    ORDER BY Number
    LIMIT 25
    ???

    It would have helped if you have shown the field names for each of those columns. And/or if you had used SELECT field1, field2, field3, ... instead of SELECT * (which you shouldn't use, if possible).
    Last edited by Old Pedant; 01-02-2013 at 10:15 PM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Apr 2011
    Posts
    16
    Thanks
    1
    Thanked 1 Time in 1 Post
    Thats brilliant, thank you


  •  

    Posting Permissions

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