Derokorian;11000321 wrote:If your inner most shows all records, what does the middle inner show? IE if you run just:
select display_id from network_display where network_id IN ( select network_id from ad_schedule where ad_id = 1142 )
Do you get what you expect? This is the step between your working query, and the final query you are trying. If this gives what you expect then could you do SHOW CREATE TABLE on the tables in question and post that info here?
Also I think this whole thing might be easier with a join, like so (untested, don't have your tables):
SELECT *
FROM display as d
INNER JOIN network_display as nd
ON d.display_id = nd.display_id
INNER JOIN network_id as n
ON n.network_id = nd.network_id
WHERE
n.ad_id = 1142
Doing this
SELECT * from display where display_id IN ( select display_id from network_display where network_id IN ( select network_id from ad_schedule where ad_id = 1142 ) )
Does exactly what I want it to do but only shows 1 row. When there is around 30.
The middle inner just links a bunch of tables together. I'm parsing all this info together from someone else's database.
CREATE TABLE IF NOT EXISTS `ad_schedule` (
`ad_schedule_id` int(11) NOT NULL AUTO_INCREMENT,
`ad_id` int(11) NOT NULL DEFAULT '0',
`network_id` int(11) NOT NULL DEFAULT '0',
`start_date` date NOT NULL DEFAULT '0000-00-00',
`end_date` date NOT NULL DEFAULT '0000-00-00',
`adinfo_file_name` varchar(128) NOT NULL DEFAULT '',
`ad_duration` int(11) NOT NULL DEFAULT '0',
`dow` int(11) NOT NULL DEFAULT '0',
`queued` enum('y','n') DEFAULT 'n',
`tod` varchar(32) DEFAULT NULL,
`restriction` varchar(16) DEFAULT NULL,
`playorder` int(11) DEFAULT NULL,
`comment` varchar(255) DEFAULT NULL,
`loopnumber` int(11) DEFAULT NULL,
`domination` int(11) DEFAULT '0',
PRIMARY KEY (`ad_schedule_id`),
KEY `ad_id` (`ad_id`),
KEY `network_id` (`network_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=16275 ;
-- --------------------------------------------------------
--
-- Table structure for table `display`
--
CREATE TABLE IF NOT EXISTS `display` (
`display_id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL DEFAULT '',
`ip_addr` varchar(32) NOT NULL DEFAULT '',
`display_location_id` int(11) NOT NULL DEFAULT '0',
`status` varchar(16) DEFAULT NULL,
`starttime` varchar(5) DEFAULT NULL,
`stoptime` varchar(5) DEFAULT NULL,
`num_screens` int(11) DEFAULT NULL,
`last_download_day_id` int(11) DEFAULT NULL,
`software_version` float DEFAULT NULL,
`venue_code` varchar(32) DEFAULT NULL,
`proprietor_code` varchar(32) DEFAULT NULL,
`suspended` int(11) DEFAULT '0',
`serial_number` varchar(64) DEFAULT NULL,
`mp_version` int(11) DEFAULT '1',
`deleted` int(11) DEFAULT '0',
PRIMARY KEY (`display_id`),
KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2036 ;
-- --------------------------------------------------------
--
-- Table structure for table `network`
--
CREATE TABLE IF NOT EXISTS `network` (
`network_id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL DEFAULT '',
`parent_id` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`network_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1859 ;
-- --------------------------------------------------------
--
-- Table structure for table `network_display`
--
CREATE TABLE IF NOT EXISTS `network_display` (
`network_id` int(11) NOT NULL DEFAULT '0',
`display_id` int(11) NOT NULL DEFAULT '0',
KEY `network_id` (`network_id`,`display_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;