If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > help to select last import

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-13-08, 17:07
demiurgen demiurgen is offline
Registered User
 
Join Date: Apr 2006
Location: Norway
Posts: 26
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.
Reply With Quote
  #2 (permalink)  
Old 08-13-08, 17:48
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
ORDER BY date_import DESC LIMIT 1
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 08-13-08, 18:04
demiurgen demiurgen is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 08-13-08, 18:19
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
SELECT list of columns
  FROM images_tbl AS table_tbl_t
 WHERE date_import = 
       ( SELECT MAX(date_import) FROM images_tbl)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 08-14-08, 02:45
demiurgen demiurgen is offline
Registered User
 
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;
Reply With Quote
  #6 (permalink)  
Old 08-14-08, 05:32
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On