SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Any mysql wizards want to give this one a try? I'm stumped.

    I'm usually pretty good a writing mysql queries, but this one has me stumped... I have a large database of links that has the following fields:

    link_id (key)
    link_title
    link_url
    link_description

    I want to pass a link with a specific link_id and have the query return an alphabetized list (based on link_title) of links with 12 links before and 12 links after the link I pass.

    Thanks,
    Ken

  2. #2
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wrong forum, but..

    Doing as 2 queries would be easier...
    Code:
    SELECT p.* FROM 
    INNER JOIN links p ON p.title < l.title
    WHERE l.linkId = :linkId
    ORDER BY l.title DESC
    LIMIT 12
    
    SELECT f.* FROM 
    INNER JOIN links p ON f.title > l.title
    WHERE l.linkId = :linkId
    ORDER BY l.title ASC 
    LIMIT 12


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
  •