Jump to content

Recommended Posts

I'm trying to create a select query that returns a list of rooms that aren't being used. I need help creating a query that shows me the rooms.room that aren't being used in visit_data.room. When a room is being occupied, my script puts the value from rooms.room into visit_data.room.

 

Any help would be greatly appreciated!!!

 

 

--
-- Table structure for table `rooms`
--

CREATE TABLE IF NOT EXISTS `rooms` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `areaid` varchar(50) NOT NULL,
  `room` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;

INSERT INTO `rooms` (`id`, `areaid`, `room`) VALUES
(1, 'ED', 'TA'),
(7, 'ED', 'TB'),
(9, 'ED', 'T2');

--
-- Table structure for table `visit_data`
--

CREATE TABLE IF NOT EXISTS `visit_data` (
  `visitid` int(11) NOT NULL AUTO_INCREMENT,
  `patientid` varchar(45) NOT NULL,
  `priority` varchar(100) NOT NULL,
  `alert1` varchar(100) DEFAULT '1',
  `alert2` varchar(100) DEFAULT '1',
  `alert3` varchar(100) DEFAULT '1',
  `cc` varchar(50) NOT NULL,
  `walkout` varchar(3) DEFAULT NULL,
  `areaid` varchar(45) NOT NULL,
  `room` varchar(45) DEFAULT NULL,
  `current_status` varchar(45) DEFAULT NULL,
  `doctor` varchar(50) DEFAULT NULL,
  `nurse` varchar(50) DEFAULT NULL,
  `reg_time` varchar(12) DEFAULT NULL,
  `discharged` varchar(45) DEFAULT NULL,
  `discharged_time` varchar(12) DEFAULT NULL,
  `disposition` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`visitid`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;

Link to comment
https://forums.phpfreaks.com/topic/209610-query-help/
Share on other sites

Thank you for actually reading my question. Your solution worked. Thanks!!!  :)

 

You can use a left join and then in the where clause specify that the value for the column in the visit_data table is null

 

 

SELECT *

FROM  `rooms`

LEFT JOIN visit_data ON rooms.room = visit_data.room

WHERE visit_data.room IS NULL 

Link to comment
https://forums.phpfreaks.com/topic/209610-query-help/#findComment-1094372
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.