AlphaSierra
AlphaSierra

Reputation: 13

How do I combine these two queries together? (MySQL)

new here and to MySQL. Wondering how I can combine these two queries together to get 1 output. I want to include all hours less or equal to 30, AND hours that equal exactly 40. I can get 2 outputs, but I am unsure how it would look if everything was put together.

The 2 commands are :

SELECT empID, hoursWorked FROM timesheet WHERE hoursWorked = 40;

SELECT empID, hoursWorked FROM timesheet WHERE hoursWorked <= 30;

Image of the CLI

Running MySQL v5.7.26 on Wampserver

Thanks !

Upvotes: 1

Views: 38

Answers (2)

Himanshu
Himanshu

Reputation: 3970

Union/Union all both the queries

    SELECT empID, hoursWorked FROM 
   timesheet WHERE hoursWorked = 40;
   Union 
   SELECT empID, hoursWorked FROM 
   timesheet WHERE hoursWorked <= 30;

Or simplest way

   SELECT empID, hoursWorked FROM 
   timesheet WHERE hoursWorked = 40
   Or hoursWorked <= 30

Upvotes: 0

Barmar
Barmar

Reputation: 782693

Use OR in the condition:

SELECT empID, hoursWorked 
FROM timesheet 
WHERE hoursWorked = 40
   OR hourseWorked <= 30;

Upvotes: 1

Related Questions