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 6133365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:13:07+00:00 2026-05-23T17:13:07+00:00

I am having trouble and need some help finding a correct SQL query. Here

  • 0

I am having trouble and need some help finding a correct SQL query. Here is my code so far:

SELECT firstname, lastname, date_of_birth 
  FROM `data` 
 WHERE firstname IN (SELECT firstname 
                       FROM `data` 
                      WHERE diagnosis_location = 'Mayo') 
   AND lastname IN (SELECT lastname 
                      FROM `data` 
                     WHERE diagnosis_location = 'Mayo') 
   AND date_of_birth IN (SELECT date_of_birth 
                           FROM `data` 
                          WHERE diagnosis_location = 'Mayo') 
   AND firstname IN (SELECT firstname 
                       FROM `data` 
                      WHERE diagnosis_location = 'Lahey') 
   AND lastname IN (SELECT lastname 
                      FROM `data` 
                     WHERE diagnosis_location = 'Lahey') 
   AND date_of_birth IN (SELECT date_of_birth 
                           FROM `data` 
                          WHERE diagnosis_location = 'Lahey')

Yes, it’s a monster of a query and probably isn’t all that efficient. But what I am trying to do is only return the first name, last name, and date of birth of all patients diagnosed at both the ‘Mayo’ location and the ‘Lahey’ location. This query does return those patients, but it returns multiple rows of the same exact data.

How could I limit it so duplicates of the same exact results are trimmed out?

  • 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-23T17:13:08+00:00Added an answer on May 23, 2026 at 5:13 pm

    Use:

      SELECT firstname, lastname, date_of_birth 
        FROM `data`
       WHERE diagnosis_location IN ('Mayo', 'Lahey')
    GROUP BY firstname, lastname, date_of_birth 
      HAVING COUNT(DISTINCT diagnosis_location) = 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just need some help to finish turning this SQL : SELECT us.name, pt.task,
I need some help adjusting the logic of my jquery function. Here's how the
I am having trouble getting my head around this query for some reason and
I'm having trouble with some jQuery stuff, please help me out. Below is my
I'm having some hard trouble finding the answer for this Is there anyway to
I'm having trouble parsing some text. Here's an example of the text: 201 BBQ
I'm having trouble incorporating a bit of logic into a large SQL query. I'm
I'd like some help with some URL rewriting magic. I am having trouble modifying
I'm having some trouble trying to get Microsoft Access 2007 to accept my SQL
I'm having trouble discovering exactly what I need to implement in order to use

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.