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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:26:38+00:00 2026-06-05T07:26:38+00:00

I don’t know if this question has been asked previously also. If so please

  • 0

I don’t know if this question has been asked previously also. If so please direct me to the link.

I have a table that has three columns name, type and date. Type can only be 4 values A, B, C and D

I want to fetch all those records which are of type A, B or C but the condition is that it should only fetch if the same name also has a type of D.

e.g. lets consider this table

Name      type    Date 
abc        A       5/7
abc        B       6/7
abc        D       7/7

xyz        A       5/7
xyz        D       6/7

lmn        A       5/7
lmn        B       6/7
lmn        C       7/7

So the deal here I need the following result set

ABC 5/7
ABC 6/7
XYZ 5/7

Because ABC and XYZ has a type D the other records of ABC and XYZ are shown. Since lmn does not have a type D it’s not included in the result set.

  • 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-06-05T07:26:39+00:00Added an answer on June 5, 2026 at 7:26 am

    To test if a record exist, you can simply use where exists :

    select * from mytable t1 where exists (
         select * from mytable t2 where t1.Name=t2.Name and t2.type="D"
    );
    

    That’s probably self explanatory but here’s a reference : http://dev.mysql.com/doc/refman/5.0/en/exists-and-not-exists-subqueries.html

    If you want to exclude the D records, you do this :

    select * from mytable t1 where t1.type<>"D" and exists (
         select * from mytable t2 where t1.Name=t2.Name and t2.type="D"
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know if this has been asked before, so point me to another question
Don't know if this has been answered before. Have custom routes to users. If
I don't know if this has been asked before, but what i'd like to
I don't know if this question is trivial or not. But after a couple
don't know if this is possible.. I'm using sqlite3 schema: CREATE TABLE docs (id
Don't know why but I can't find a solution to this. I have 3
don't know better title for this, but here's my code. I have class user
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
Don't know why but font is not displaying.Please help. CSS(in css folder): style.css: @font-face
I don't know whether this is really possible, but I'm trying my best. If

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.