SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Evangelist Tecknowjnkie's Avatar
    Join Date
    Nov 2004
    Location
    Mission Viejo
    Posts
    403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Make Row 15 Row 1 and push the rest down

    HI All,

    Sorry if this is an easy SQL sentence. What would the sentence be to update row 15 to 1 and push the rows down 1?

    Thank you in advance

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    can you give some example rows please?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist Tecknowjnkie's Avatar
    Join Date
    Nov 2004
    Location
    Mission Viejo
    Posts
    403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


    Here ya go thank you. I thought maybe I could ORDER BY title but that will not work

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    i can't read that

    how about a cut and paste, using plain text

    i need to see the column names, and i need you to explain which column has the values that you want to "push", and how the values in that column are assigned for new rows
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Evangelist Tecknowjnkie's Avatar
    Join Date
    Nov 2004
    Location
    Mission Viejo
    Posts
    403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Table is like this

    table name: press
    Columns:
    id 1st
    title 2nd
    release 3rd
    image 4th

    The last row is 15 and I need to make that row 1 and push the rest down/

    Thank you, Good Lord r937, 6705 posts; that is not your baby picture is it?

    Off Subject: TOAD for MySQL or PHPAdmin?

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    okay, what is it you really want? do you want only 15 rows, or do they have to have the actual numbers 1 through 15, and if so, why?

    yes, that's me in 1953

    off subject: mysql-front
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Evangelist Tecknowjnkie's Avatar
    Join Date
    Nov 2004
    Location
    Mission Viejo
    Posts
    403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WHen I entered the data in the DB it went in order of newest to last. Then when I entered a new press release, it shows up last when displayed. What I need to do is have row 15 populate first in the loop and then 1-14 after that? I am afrraid you are going to reply with a SQL sentence and I will be feeling dumb.

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    so what you really want is to show only the top 15 in the correct date sequence?

    i mean, if this is good data, it'd be a shame to erase the older ones, what if some day you want to have a history of old press releases? wouldn't that be nice? and disk space is really cheap, you could keep history of thousands of them a lot easier that "pushing" numbers down to 15 and you would get splendidly efficient performance for your top 15 report if you also create an index on the date of the news release
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  9. #9
    SitePoint Evangelist Tecknowjnkie's Avatar
    Join Date
    Nov 2004
    Location
    Mission Viejo
    Posts
    403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you R937

    Forgive my nayitivity, by index do you mean a new column with DATETIME?

    Currenlty there are only 15 PRess Releases in the table so rebuild and putting the data back in would be easy.

    Sould I altar table with a new coulumn with TIMEDATE format?

  10. #10
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    yes, alter the table and a a column with DATE datatype, or, if you need exact time as well as date, with DATETIME datatype

    then use order by datecolumn desc limit 15
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •