Jump to content

JipThePeople

Members
  • Posts

    51
  • Joined

  • Last visited

Everything posted by JipThePeople

  1. Thx so much for the response. My table has 9 records (currently) for 3 different file id's (i.e., I need to retrieve the most recent record for each file id = 3 records returned). Unfortunately, the query you provided returns multiple records for each file_id. Any other ideas will be great appreciated.
  2. Can you please provide an example?
  3. I have a table containing records of files and scores which also contain a date the record was inserted and the file_id as well as other fields. I want to select the most recent score for each file_id. For instance, there will be multiple records for a file_id corresponding to the latest score assigned to that file. There will be different file_id's in the table each with multiple records. My goal is to select one record per each unique file_id retrieving only the last record inserted (per the submit_date field). I can retrieve a single record (the most recent record inserted) with this query, but I need the most recent record for each unique file_id in the table. SELECT `score` FROM `file_grade_answers` WHERE `submit_date` = (SELECT MAX(`submit_date`) FROM `file_grade_answers`) Here is the table I am using for this question: CREATE TABLE IF NOT EXISTS `file_grade_answers` ( `filegrade_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `file_id` int(10) unsigned NOT NULL, `reviewer_id` varchar(100) NOT NULL, `owner_at_review` varchar(100) NOT NULL, `process_at_review` int(10) unsigned NOT NULL, `question_ids` varchar(100) NOT NULL, `answers` varchar(100) NOT NULL, `recommendations` blob NOT NULL, `submit_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `possible_points` int(10) unsigned NOT NULL, `actual_points` int(10) unsigned NOT NULL, `score` int(10) unsigned NOT NULL, PRIMARY KEY (`filegrade_id`) ) Any advice will be greatly appreciated.
  4. Thx for the replies. I had to do it this way: SELECT * FROM `users` WHERE `last_name` >='A' AND `last_name` < 'G' This query returns records as expected.
  5. Query does not throw an error (i.e., syntax is good), it just won't return any records and there are user names in the table with last names that begin with the range of letters.
  6. Unfortunately, all I can find is LIKE '[A-F]%' But that doesn't work with MySQL. Has anyone else had this issue?
  7. MySQL version: 5.1.54-community I am executing the SQL within PHP MyAdmin 3.3.8.1 This will successfully return records (last names beginning with 'B'): SELECT * FROM `users` WHERE `last_name` LIKE 'B%' However, this query is SUPPOSED to return records of users with last names that begin with letters A-F: SELECT * FROM `users` WHERE `last_name` LIKE '[A-F]%' Here is the table I am querying: CREATE TABLE IF NOT EXISTS `users` ( `userid` varchar(25) NOT NULL DEFAULT '', `first_name` varchar(50) NOT NULL DEFAULT '', `last_name` varchar(50) NOT NULL DEFAULT '', `email` varchar(100) NOT NULL DEFAULT '', `work_address1` varchar(100) NOT NULL DEFAULT '', `work_address2` varchar(100) DEFAULT '', `work_city` varchar(100) NOT NULL DEFAULT '', `work_state` char(2) NOT NULL DEFAULT '', `work_zip` varchar(10) NOT NULL DEFAULT '', `home_address1` varchar(100) DEFAULT '', `home_address2` varchar(100) DEFAULT '', `home_city` varchar(100) DEFAULT '', `home_state` char(2) DEFAULT '', `home_zip` varchar(10) DEFAULT '', `work_phone` varchar(20) NOT NULL DEFAULT '', `home_phone` varchar(20) DEFAULT '', `mobile_phone` varchar(20) DEFAULT '', `fax` varchar(20) DEFAULT '', `primary_phone` varchar(100) NOT NULL DEFAULT '', `manager` varchar(100) DEFAULT '', `connection_type` varchar(100) DEFAULT '', `organization` varchar(255) DEFAULT NULL, `group_id` int(10) unsigned DEFAULT '1', `must_update` int(2) unsigned NOT NULL DEFAULT '0', `must_change_pw` int(1) unsigned NOT NULL DEFAULT '0', `last_updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `use_cached_login` int(1) unsigned NOT NULL DEFAULT '0', `active` int(2) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`userid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; My goal is to select users with last names that begin with a range of letters (e.g., A-F). Any help is greatly appreciated.
×
×
  • 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.