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

  • SEARCH
  • Home
  • 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 146593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:37:51+00:00 2026-05-11T08:37:51+00:00

My database isn’t actually customers and orders, it’s customers and prescriptions for their eye

  • 0

My database isn’t actually customers and orders, it’s customers and prescriptions for their eye tests (just in case anyone was wondering why I’d want my customers to make orders less frequently!)

I have a database for a chain of opticians, the prescriptions table has the branch ID number, the patient ID number, and the date they had their eyes tested. Over time, patients will have more than one eye test listed in the database. How can I get a list of patients who have had a prescription entered on the system more than once in six months. In other words, where the date of one prescription is, for example, within three months of the date of the previous prescription for the same patient.

Sample data:

Branch  Patient DateOfTest 1      1          2007-08-12 1      1          2008-08-30 1      1          2008-08-31 1      2          2006-04-15 1      2          2007-04-12 

I don’t need to know the actual dates in the result set, and it doesn’t have to be exactly three months, just a list of patients who have a prescription too close to the previous prescription. In the sample data given, I want the query to return:

Branch   Patient 1       1 

This sort of query isn’t going to be run very regularly, so I’m not overly bothered about efficiency. On our live database I have a quarter of a million records in the prescriptions table.

  • 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. 2026-05-11T08:37:51+00:00Added an answer on May 11, 2026 at 8:37 am

    Something like this

    select p1.branch, p1.patient from prescription p1, prescription p2 where p1.patient=p2.patient and p1.dateoftest > p2.dateoftest and datediff('day', p2.dateoftest, p1.dateoftest) < 90; 

    should do… you might want to add

    and p1.dateoftest > getdate() 

    to limit to future test prescriptions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The value for a field (phone number) isn't being correctly entered into the database.
I'm using SQLite database. The problem is that data isn't written to base. NSLog
Im looking to run PostgreSQL in RAM for performance enhancement. The database isn't more
I think database operations isn't explained very well, on guide . I couldn't understand
I have inherited a SQL server database which isn't normalised and is giving me
I'm transferring an existing Sentry install to a new machine, so my database isn't
I'm outputting values from a database (it isn't really open to public entry, but
I am executing the follwing statements in php,mysql. The database isn't gettig updated. I
I've just started a job and have identified an issue in which the database
database name customdata jobNo CustomerName Country Tel Item 1 John USA 045 Mouse 2

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.