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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:12:46+00:00 2026-06-04T02:12:46+00:00

I have a directory table in a MySQL database that contains user ID’s, user

  • 0

I have a directory table in a MySQL database that contains user ID’s, user types, and assorted other directory information. There are two types of users: employee and student. The primary key is (userID, userType), so any given user can have an employee record and a student record (in the event that they are both an employee and a student).

I would like to perform queries on a subset of this table, so that:

  • If a user has only an employee xor a student record, that record is used, and
  • If a user has both an employee and a student record, the employee record is used and the student record is ignored

I will not need to include an ORDER BY clause in the queries, but they can include rather complicated WHERE clauses (including queries on userType itself).

Ideally, I would like to do this without having to create extra tables or views, but if an extra view is necessary I can ask the sysadmin for CREATE VIEW permissions.

  • 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-04T02:12:48+00:00Added an answer on June 4, 2026 at 2:12 am

    Didn’t actually test it, but something like this should work:

    SELECT *
    FROM directory
    WHERE
        userType = 'employee'
        OR userID NOT IN (
            SELECT userID
            FROM directory
            WHERE userType = 'employee'
        )
    

    In plain English: select all employees (left of OR) and all students for which there are no corresponding employees (right of OR).

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

Sidebar

Related Questions

I have a form that a user fills out, which submits information to my
I have a folder of jpegs, and a MySQL database that I hope to
I have a PHP form that is inserting information into a database. It all
I have directory A with files matching directory B. Directory A may have other
I have a directory with PDF files that I need to create an index
I have a table named users and each row (user) has an image. The
I have a MySQL table which basically serves as a file index. The primary
I have a table of products in my sql database. Each product has an
I have a url problem. When the user types in this url: www.example.com/username, it
I have a while loop that goes through a table and I echo the

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.