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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:55:07+00:00 2026-05-20T03:55:07+00:00

I have two MySQL tables, tblclients and tblservices . Each record in tblservices represents

  • 0

I have two MySQL tables, tblclients and tblservices. Each record in tblservices represents a service we provide for a client and there can be many services per client. Both tables have a ‘status’ field, in tblclients it is either ‘active’ or ‘inactive’ and in tblservices it is either ‘active’ or ‘terminated’.

I need to write a SQL statement which will output a list of active clients which have no active services so that I can write a php script which will make the clients inactive.

I understand how to list all clients which have a service which is terminated, but I don’t understand how to list clients which have no active services (all terminated). Is there a way to query this in SQL using subqueries or the like. So far I have:

SELECT tblclients.id, tblclients.email, tblservices.status 
FROM tblclients JOIN tblservices on tblclients.id = tblservices.userid 
WHERE tblclients.status="active" AND tblservices.status="terminated";
  • 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-20T03:55:07+00:00Added an answer on May 20, 2026 at 3:55 am

    Try using WHERE [NOT] EXISTS (I’ve munged your table names for readability):

    SELECT * FROM clients WHERE
        clients.status = 'active' AND
        NOT EXISTS (SELECT * FROM services WHERE
            services.userid = clients.id AND
            services.status = 'active'
        );
    

    This’ll give you all your active clients that don’t have any active services (these will include clients with no services at all).

    Hope this helps!

    Update: To exclude clients with no services at all, just add that condition, too:

    SELECT * FROM clients WHERE
        clients.status = 'active' AND
        EXISTS (SELECT * FROM services WHERE services.userid = clients.id) AND
        NOT EXISTS (SELECT * FROM services WHERE
            services.userid = clients.id AND
            services.status = 'active'
        );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two mysql tables: Item containing items that one can buy: CREATE TABLE
I have two MySQL tables and I would like to know if there is
I have two mysql tables, one containing details on cars and one containing all
I have two mysql tables, courses and student_courses, I need to get unique course_names
I have two mysql tables: TableA has 10,000 records TableB has 2,000 records. I
i have two mysql tables tableA col1 col2 SIM1 ..........col24 ----------------------------------- a x 1
I have two MySql tables as shown below with the data shown: CREATE TABLE
I have two mysql tables - a sales table: +----------------+------------------------------+------+-----+---------+-------+ | Field | Type
i have two mysql tables tableA colA1 colA2 1 whatever 2 whatever 3 whatever
I have two MySQL tables, and I want to find and replace text strings

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.