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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:42:55+00:00 2026-05-23T02:42:55+00:00

I have a table id|customer_id|comment 1 34 good 2 23 bad 3 34 regular

  • 0

I have a table

id|customer_id|comment
1   34                       good
2   23                       bad
3   34                      regular
4   76                       longterm
5   34                       bad
6   23                      good

We can see that one customer_id has different comment (ex – 34 has good regular bad)
I am trying to pull records from the above table where comment is “good and also bad” and group by customer_id so in the result I should see the records id => 1, 5, 2, 6

Can someone please help me in writing this where clause.

regards

  • 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-23T02:42:56+00:00Added an answer on May 23, 2026 at 2:42 am

    To have one row of data reference another row, you need a join. In this case you’ll want to join comment against itself:

    select distinct a.customer_id 
    from comments a 
    join comments b on a.customer_id = b.customer_id and a.id < b.id 
    where a.comment = 'good'
    and b.comment = 'bad'
    

    I’ve chosen the a.id < b.id syntax to avoid doing the same join in both directions, resulting in duplicate work. By specifying distinct, you’ll see each customer only once.

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

Sidebar

Related Questions

Good afternoon I have a table that has customer id, name, computer, laptop, blah,
I have table customer and table contract with one-many relationship (1 customer has many
I have a self-referencing table (Customers) and a table that will link to one
Here is a simple example: Assume I have a customer table that has a
I have a table customer that stores a customer_id, email and reference. There is
Let's say I have a Customer table which has a PrimaryContactId field and a
i'm trying to get optimize an very old query that i can't wrap my
I have a log table that is inherited by several tables: CREATE TABLE log
I have table as below ACCOUNT CUSTOMER_ID PAYING_ACCOUNT_ID PARENT_ACCOUNT_ID ACCOUNT_ID COMPANY_ID 24669 24669 24669
I have table invoices with field customer_id and some others fields. I need select

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.