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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:31:14+00:00 2026-06-07T15:31:14+00:00

This probably has a simple solution to it but i can’t wrap my head

  • 0

This probably has a simple solution to it but i can’t wrap my head around it at the moment.

My table looks like this

|id|company_id|shift_type_id|user_id|date|create_at|updated_at|

I’m trying to list shifts that belong to a specific user

SELECT * FROM shifts WHERE user_id = 1

Then make a selection between two dates

SELECT * FROM shifts WHERE user_id = 1 and date BETWEEN '2012-07-09' and '2012-07-15'

Exclude all shifts that are on Saturday and Sunday

SELECT * FROM shifts WHERE user_id = 1 and date BETWEEN '2012-07-09' and '2012-07-15' and DAYNAME(date) != "Saturday" and DAYNAME(date) != "Sunday"

Now the tricky part (for me), on top of all this i want to exclude shifts that are on Friday and with a specific shift_type_id in this case 6. I tried by doing this

SELECT * FROM shifts WHERE user_id = 1 and date BETWEEN '2012-07-09' and '2012-07-15' and DAYNAME(date) != "Saturday" and DAYNAME(date) != "Sunday" and (DAYNAME(date) != "Friday" and shift_type_id != 6)

This doesn’t work, i dont quite understand why and i dont know how to solve this problem. I’ve seen some solutions that use subqueries and exclude the results from the main results but i want keep this easy to build on so that i can create a query from a set of rules.

I’m doing this in a rails3 project and this is what that looks like

@user.work_hours.where('shifts.date between ? and ?', params[:start_date], params[:end_date]).where('DAYNAME(shifts.date) != "Sunday" and DAYNAME(shifts.date) != "Saturday" AND (DAYNAME(shifts.date) != "Friday" and shifts.shift_type_id != 6)')

  • 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-07T15:31:17+00:00Added an answer on June 7, 2026 at 3:31 pm

    From what you’ve said you need

    SELECT * FROM shifts WHERE user_id = 1 and date BETWEEN '2012-07-09' and '2012-07-15' and DAYNAME(date) != "Saturday" and DAYNAME(date) != "Sunday" and (DAYNAME(date) != "Friday" and shift_type_id = 6)
    

    Exclude fridays with a shift id of 6, yours was exclude fridays that don’t have an id of 6.

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

Sidebar

Related Questions

New Rails programmer here. There is probably a pretty simple solution to this, but
I know this probably has been asked before but I am having issues with
This has probably been answer already but I am trying to return the primary
I realize this question has probably been asked numerous times, but I have not
I know this has been asked probably a thousand times, but I've been biting
This probably sounds like a terrible idea at first glance, but here is my
I know this probably really simple but Im not sure what im doing wrong...
This is probably a stupid question but I can not seem to either remember
Probably a long question for a simple solution, but here goes... I have a
I guess this is a really simple question and, probably, one that has been

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.