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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:33:49+00:00 2026-05-11T15:33:49+00:00

I have a set of three tables: Dining_Tables; +——————–+————–+——+—–+———+——-+ | Field | Type |

  • 0

I have a set of three tables:

 Dining_Tables; +--------------------+--------------+------+-----+---------+-------+ | Field              | Type         | Null | Key | Default | Extra | +--------------------+--------------+------+-----+---------+-------+ | dining_table       | int(11)      | NO   | PRI | NULL    |       | | bus_boy            | varchar(35)  | NO   |     | NULL    |       | | waiter             | varchar(35)  | NO   |     | NULL    |       | | server             | varchar(35)  | NO   |     | NULL    |       | +--------------------+--------------+------+-----+---------+-------+  Poker_Tables; +--------------------+--------------+------+-----+---------+-------+ | Field              | Type         | Null | Key | Default | Extra | +--------------------+--------------+------+-----+---------+-------+ | poker_table        | int(11)      | NO   | PRI | NULL    |       | | dealer             | varchar(35)  | NO   |     | NULL    |       | | pit_boss           | varchar(35)  | NO   |     | NULL    |       | +--------------------+--------------+------+-----+---------+-------+  Computer_Tables; +--------------------+--------------+------+-----+---------+-------+ | Field              | Type         | Null | Key | Default | Extra | +--------------------+--------------+------+-----+---------+-------+ | computer_table     | int(11)      | NO   | PRI | NULL    |       | | programmer         | varchar(35)  | NO   |     | NULL    |       | +--------------------+--------------+------+-----+---------+-------+ 

Each of these rows has globally unique table id associated with it: (dining_table, poker_table, computer_table) The other columns store the First/Last name of the person fulfilling the roll.

In my model, a single individual can be doing multiple things. For example, Joe Smith could be simultanously sitting at a computer_table as a programmer, sitting at a poker_table as a dealer, and waiting on a dining_table as a waiter.

My question is this: I want a query that will allow me to retrieve all the table_ids for a given person. Specifically, the query would then return a list of table_ids that Joe Smith is currently at.

I could do something along these lines:

 select dining_table from Dining_Tables where        bus_boy = 'Joe Smith' or       waiter = 'Joe Smith' or        server = 'Joe Smith';  select poker_table from Poker_Tables where        dealer = 'Joe Smith' or        pit_boss = 'Joe Smith';  select computer_table from Computer_Tables where        programmer = 'Joe Smith'; 

However, that’s three seperate queries and I’d really prefer to avoid doing that if possible. Can I do it in one query using joins?

  • 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. 2026-05-11T15:33:50+00:00Added an answer on May 11, 2026 at 3:33 pm

    If you want to return it in a single query you could use a UNION statement that would join those three queries into one.

    select dining_table as Table from Dining_Tables where        bus_boy = 'Joe Smith' or       waiter = 'Joe Smith' or        server = 'Joe Smith' UNION select poker_table as Table from Poker_Tables where        dealer = 'Joe Smith' or        pit_boss = 'Joe Smith' UNION select computer_table as Table from Computer_Tables where        programmer = 'Joe Smith' 

    Although it is three statements, it would be returned as a single result set.

    If you separated your ‘jobs’ into a separate table, it would make querying a lot easier.

    I could imagine something along the lines of:

    Tables, TableTypes, Persons, Roles, TableRoles

    TableTypes ID    TypeName ----------------------- 1     Dining 2     Poker 3     Computer  Tables ID    TableTypeID ---------------------------- 1     1 2     1 3     2 4     3 5     2 6     3  Persons ID    Name --------------------------- 1     Joe Smith 2     Mary Belcher 3     Norma Grey   Roles ID    RoleName ----------------------------- 1     Bus Boy 2     Waiter 3     Server 4     Dealer 5     Pit Boss 6     Programmer   TableRoles TableID    RoleID    PersonID ----------------------------- 1          1         1 //etc //etc 

    This would make all of your querying very simple and straightforward and also makes it scalable (so you can add more roles to each table without mucking your database)

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

Sidebar

Related Questions

I have made three tables: CREATE TABLE country_ ( id_country int NOT NULL IDENTITY(219,1),
I have a very generic set of three tables that store all of my
I have the following result set from a join of three tables, an articles
I have three tables as shown below Emp ---- empID int empName deptID empDetails
I have three tables : ImportBatch PatientChartImages PatientChartBatchMapping (this table has foreign key to
I have set up Sphinx to index three tables in a MySQL database, each
I have three tables set up in a MySQL database called event, status and
I have a database with three tables set up like this: Users : username,
I have three tables: User -- contains users Group -- contains a set of
I have a database with three tables, user, update and error. I have set

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.