MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 27th, 2013, 07:53 PM
zxcvbnm's Avatar
zxcvbnm zxcvbnm is offline
A Change of Season
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2004
Posts: 1,676 zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 17 h 46 m
Reputation Power: 71
What is the best approach to find the latest value added to multiple tables?

Hello;

In brief: There are 2 listings: Galleries and Events.
They both have photos stored in seperate tables(gallery_photos, event_photos). Admin can add photos to both galleries and events and it inserts into the appropriate table (gallry_photos or events_photos).

How can I get the name of a gallery OR event that has the newset photo added to it. Is it even possible?

(Please note: I am not looking for 1 gallery and 1 event. I am looking the latest gallery or event.)

Code:
CREATE TABLE IF NOT EXISTS `sincity_event_photos` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `event_id` int(11) NOT NULL,
  `photo` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=97 ;
Code:
CREATE TABLE IF NOT EXISTS `sincity_events` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `recurring` varchar(255) NOT NULL,
  `title` varchar(255) NOT NULL,
  `about` text NOT NULL,
  `photo` varchar(255) NOT NULL,
  `musicians` text NOT NULL,
  `type` varchar(255) NOT NULL,
  `date` date NOT NULL,
  `display_date` varchar(255) NOT NULL,
  `price` int(11) NOT NULL,
  `recurring_day` varchar(255) NOT NULL,
  `thumbnail_photo` varchar(255) NOT NULL,
  `main_photo` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1859 ;
 
Code:
CREATE TABLE IF NOT EXISTS `sincity_galleries` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `about` text NOT NULL,
  `date_added` date NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=24 ;
Code:
CREATE TABLE IF NOT EXISTS `sincity_galleries_photos` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `gallery_id` int(11) NOT NULL,
  `photo` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=174 ;

Reply With Quote
  #2  
Old January 28th, 2013, 03:24 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 2,352 swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 4 Days 9 h 55 m 58 sec
Reputation Power: 390
Something like

Code:
select <columnsOfInterest>
  from (select <columnsOfInterest>  
          from sincity_galleries
         union all
        select <columnsOfInterest>
          from sincity_events) dt
 order by date_added desc
 limit 1


The number of columns in the select list of the select queries in the union must be the same. Tthe type for each column in the first select must be compatible with the corresponding column in the second select list.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > What is the best approach to find the latest value added to multiple tables?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap