Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2006
    Location
    Norway
    Posts
    26

    Unanswered: help to select last import

    i need help to query my image gallery database for the batch of images that i imported last (like in iphoto).
    i have a column called date_import with the type of date that contains the dates of all the images that i have imported.

    in pseudo-code it may be something like this:
    SELECT * FROM images_tbl WHERE date_import is nearest today;
    i think that would always give me the last set of images i imported whether its two days ago or a month.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    ORDER BY date_import DESC LIMIT 1
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Apr 2006
    Location
    Norway
    Posts
    26
    but that will only show me the last image.
    i need to show the last batch of images.

    i use this in iphoto all the time. the reason i find it handy is because when i come home from a holiday or some event and i empty my camera, it may take weeks before i sort all of them into different albums and such. so by using last import i won't put images that are already there into the albums.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT list of columns
      FROM images_tbl AS table_tbl_t
     WHERE date_import = 
           ( SELECT MAX(date_import) FROM images_tbl)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Apr 2006
    Location
    Norway
    Posts
    26
    AWESOME!
    that worked.
    but do i have to use the AS table_tbl_t?
    it still works without it.

    my query is now:
    SELECT * FROM albums INNER JOIN images ON albums.id = images.album_id AND date_import = ( SELECT MAX(date_import) FROM images) AND status = 'active' LIMIT 0, 9;

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by demiurgen
    but do i have to use the AS table_tbl_t?
    it still works without it.
    no, you don't, i was just teasing
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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