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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:49:52+00:00 2026-05-28T03:49:52+00:00

I have 2 tables in my database that look like so: clients +————-+ |

  • 0

I have 2 tables in my database that look like so:

clients
+-------------+
| id   | sms  |
|------+------|
| 1    | 0    |
| 2    | 1    |
| 3    | 1    |
| 4    | 1    |
+------+------+

clients_lists_relationships
+----------------------+
| listid   | clientid  |
|----------+-----------|
| 1        | 1         |
| 1        | 2         |
| 2        | 1         |
| 3        | 1         |
+----------+-----------+

Now what I’m trying to do is get a list of clients who are in a bunch of lists. I do that like so:

SELECT c.id, 
       l.* 
FROM   clients AS c, 
       clients_lists_relationships AS l 
WHERE  c.id = l.clientid 
       AND c.sms = '1' 
       AND ( l.listid = '1' 
              OR l.listid = '2' );

This does give me a list of the clients that I need. But because a client can be in more than one list I get the same client more than once. How would I limit this to only one row for each client no matter how many lists they are in?

  • 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-28T03:49:52+00:00Added an answer on May 28, 2026 at 3:49 am

    Use GROUP BY:

    SELECT c.id, 
           l.listid
    FROM clients c
    INNER JOIN clients_lists_relationships l
    ON c.id = l.clientid
    WHERE  c.sms = 1
           AND l.listid IN (1,2)
    GROUP BY c.id
    

    Note that by doing this you lose information on which lists the client was a member of. This means that you should probably not select anything from client_lists_relationships as this information is either redundant (clientid) or incomplete (listid).

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

Sidebar

Related Questions

I have two tables in a teradata database that look like this accounts account_number
I have a database that consists of two tables, which look like this: users
I have two tables in my database that look like this CREATE TABLE IF
I have a view that will look like this: I'm trying to figure out
When I have tables in my database that have PK/FK relationships (int) and when
I have several database tables that just contain a single column and very few
I have two tables in my database schema that represent an entity having a
I have the following tables in my database that have a many-to-many relationship, which
If you have a set of tables in the database that strictly consist of
In my database I have tables that define types for example Table: Publication Types

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.