Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 695429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:57:31+00:00 2026-05-14T02:57:31+00:00

…besides the fact that I am a total amateur? My table is set up

  • 0

…besides the fact that I am a total amateur?

My table is set up like this:

CREATE TABLE `messages` (
 `id` int(6) unsigned NOT NULL AUTO_INCREMENT,
 `patient_id` int(6) unsigned NOT NULL,
 `message` varchar(255) NOT NULL,
 `savedate` int(10) unsigned NOT NULL,
 `senddate` int(10) unsigned NOT NULL,
 `SmsSid` varchar(40) NOT NULL COMMENT 'where we store the cookies
from twilio',
 `sendorder` tinyint(3) unsigned NOT NULL COMMENT 'the order we want
the msg sent in',
 `sent` tinyint(1) NOT NULL COMMENT '0=queued, 1=sent,
2=sent-unqueued,4=rec-unread,5=recd-read',
 PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=143 ;

I need a query that will

SELECT * FROM `messages` WHERE `senddate` < $now AND `sent` = 0 (AND LIMIT
TO ONLY ONE RECORD PER `patient_id`)

I’ve tried the following:

SELECT * 
FROM `messages`
WHERE `senddate` IN 
    (SELECT `patient_id`, max(`senddate`)
     GROUP by `patient_id`) 
AND `senddate` < $now AND `sent` = 0 ;

But I get this error:
MySQL client version: 5.1.37

`#1064 – You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server
version for the right syntax to use
near ‘GROUP by patient_id) AND
senddate < 1270093898 AND sent = 0
LIMIT 0, 30’ at line 5

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:57:31+00:00Added an answer on May 14, 2026 at 2:57 am

    This query should return one record per patient_id while preserving the conditions that your initial query contains:

    SELECT `patient_id`, max(`senddate`)
    FROM `messages`
    WHERE `senddate` < $now AND `sent` = 0
    GROUP BY `patient_id`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
so I did $subject = 'sakdlfjsalfdjslfad <a href=something/8230>lol is that true?</a> lalalala'; $subject =
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
An Arabic name shall be sent via SOAP. The name is encoded like this:
CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example: require 'cgi' CGI.unescapeHTML('&#8230;')
what about this one: I want to format the currentTime displayed by a videoPlayer
English is not my native language. I need a software to spellcheck and correct
(tl;dr: see summary at the bottom.) I am implementing an application that pulls content
I want to run this <!-- This will remove the tag --> <xsl:template name=remove-html>
I see that some rss on xml have strange strings. For example, ... is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.