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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:48:40+00:00 2026-05-27T18:48:40+00:00

I know this is possible I just dont know how to the code or

  • 0

I know this is possible I just dont know how to the code or how to phrase it to search for the answer I need. I am pretty sure I need to use JOIN but again I am finding it hard to find an example to get the correct syntax.

I have 3 tables. An events table, which contains events that occur on different machines and their times. So for questions purposes events had 4 fields:

EVENTS

  • event_id (primary key, auto_increment)
  • machine_id (foreign key)
  • time_in
  • time_out
  • I then have a table “machines” which lists all of the machines:


    MACHINES

  • id (key)
  • name
  • department_id (foreign key)
  • then lastly i have the Department table:


    DEPARTMENTS

  • id (key)
  • name
  • I want to select all events that occur in a department. So say i want all events from events where the department_id of the machine the event occured on is = 1.

    • 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-27T18:48:40+00:00Added an answer on May 27, 2026 at 6:48 pm
      SELECT E.event_id, E.machine_id, E.time_in, E.time_out
      FROM EVENTS E
      INNER JOIN MACHINES M ON E.machine_id=M.machine_id
      WHERE M.department_id = 1
      

      By the way, if you don’t know the department id but know the name of the department, you can do an additional JOIN and use the department name:

      SELECT E.event_id, E.machine_id, E.time_in, E.time_out
      FROM EVENTS E
      INNER JOIN MACHINES M ON E.machine_id=M.machine_id
      INNER JOIN DEPARTMENTS D ON M.department_id=D.department_id
      WHERE D.Name = 'Accounting'
      
      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
        • Report

    Sidebar

    Related Questions

    I know this is possible but I'm not really sure where to start. Has
    I know this is probably possible using Streams, but I wasn't sure the correct
    I don't know whether this is really possible, but I'm trying my best. If
    I know this rather goes against the idea of enums, but is it possible
    I know this is very evil, but is it possible to add an object
    Whether this is possible I don't know, but it would mighty useful! I have
    Possible Duplicate: Does anyone beside me just NOT get ASP.NET MVC? I dont know
    I don't know if this is possible, but I have 3 DIV's that have
    I know this is possible to be done using javascript, and I presume I
    I don't know if this is possible or not, or if my limited knowledge

    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.