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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:52:12+00:00 2026-05-29T05:52:12+00:00

Table 1: Users | profile_id | name | ———————— | 1 | Joe |

  • 0

Table 1: Users

| profile_id | name    |
------------------------
| 1          | Joe     |
| 2          | Jane    |
| 3          | Jill    |
| 4          | Jeffery |

Table 2: User and Role to Team Lookup

| team_id | profile_id | role   |
---------------------------------
| 1       | 1          | coach  |
| 1       | 2          | player |
| 2       | 4          | coach  |
| 2       | 1          | player |

The scenario is that Jill is building a team, and the restriction is that you cannot be a player on more than one team. So I’m trying to build a query that pulls up those eligible to join Jill’s team.

My first attempt was:

SELECT `users`.`profile_id`
FROM `users` LEFT JOIN `user_role_to_team_lookup` AS `utr` USING(`profile_id`)
WHERE `utr`.`role` != 'player' OR `utr`.`role` IS NULL

The problem is that because Joe is a coach, he matches the criteria~ even though he is also already a player.

What would be the proper way to exclude users that are already players from 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-05-29T05:52:13+00:00Added an answer on May 29, 2026 at 5:52 am

    I would write this without the subquery that most people use:

    SELECT u.profile_id
    FROM users AS u 
    LEFT OUTER JOIN user_role_to_team_lookup AS utr 
      ON u.profile_id = utr.profile_id AND utr.role = 'player'
    WHERE utr.profile_id IS NULL
    

    In other words, look for a user who is already a player. Those who aren’t a player will match no rows in the outer join, and therefore any column of utr will be NULL.

    But it’s best to put the condition in the ON clause of the join.

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

Sidebar

Related Questions

I have a user table 'users' that has fields like: id first_name last_name ...
I have dbml with single table users i want add partial class for User
I have a DataGridView binded to this table: [Users] ID Name -- ---- 11
Users table: user_id | avatar ---------------------------------- 1 | file-name.jpg 2 | friendly-ghost.jpg Profile views
I have three tables, table one (tableA) containing users data like name and email,
if i have this table: users ----- id_users (pk) age name gender salary it
I have table Users which contains columns: id, name, points, extra_points. How can I
using php and mysql I have two tables, a users table and a profiles
Below is my table, a User could have multiple profiles in certain languages, non-English
I have a table users which has a primary key userid and a datetime

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.