will35010 Posted January 19, 2010 Share Posted January 19, 2010 I want to run a select query like: "SELECT visitid FROM visit_data WHERE patientid = '$patientid'"; I don't want it to return all the results. I only want the highest numbered visitid. How do I do that? Thanks! Here is the table: CREATE TABLE IF NOT EXISTS `visit_data` ( `visitid` int(11) NOT NULL AUTO_INCREMENT, `patientid` varchar(45) NOT NULL, `date` date NOT NULL, `cc` varchar(50) NOT NULL, `walkout` varchar(3) DEFAULT NULL, `location` varchar(45) NOT NULL, `room` varchar(45) DEFAULT NULL, `current_status` varchar(45) NOT NULL, `reg_time` timestamp NULL DEFAULT NULL, `discharged` varchar(45) DEFAULT NULL, `discharged_time` timestamp NULL DEFAULT NULL, `disposition` varchar(100) DEFAULT NULL, PRIMARY KEY (`visitid`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; Quote Link to comment https://forums.phpfreaks.com/topic/189061-select-query-help/ Share on other sites More sharing options...
o3d Posted January 19, 2010 Share Posted January 19, 2010 "SELECT max(visitid) as max_visitid FROM visit_data WHERE patientid = '$patientid'" Quote Link to comment https://forums.phpfreaks.com/topic/189061-select-query-help/#findComment-998234 Share on other sites More sharing options...
will35010 Posted January 19, 2010 Author Share Posted January 19, 2010 "SELECT max(visitid) as max_visitid FROM visit_data WHERE patientid = '$patientid'" Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/189061-select-query-help/#findComment-998237 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.