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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:10:20+00:00 2026-05-31T23:10:20+00:00

I am currently working on a database which stores information which allows users to

  • 0

I am currently working on a database which stores information which allows users to make reservations at a restaurant.

I am trying create a SQL statement which returns the times which appear less than twice in the reservations table.

At the moment I have this but this only returns the times which do not appear in the reservations table at all.

SELECT *
FROM TIME
WHERE
    TIME NOT IN (
        SELECT reservation.a_time
        FROM 
            RESERVATION
        JOIN TIME ON 
            reservation.a_time = time.time
        WHERE
            reservation.a_date = :the_date
    )
ORDER BY time;

The above statement returns all times which are not in the reservations table. However how would I return all times which appear in the reservations table including those that appear once but not those that appear twice?

Thanks

  • 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-31T23:10:21+00:00Added an answer on May 31, 2026 at 11:10 pm
    select
      *
    from
      TIME t
    where
      (select 
        count(r.a_time) 
      from 
        RESERVATION r 
      where
        r.a_time = t.time and
        r.a_date = :the_date) < 2
    

    or

    select
      t.time /* and maybe other field, which you need to add to Group By as well */
    from
      TIME t
      left join RESERVATION r on r.a_time = t.time and r.a_date = :the_date
    group by
      t.time
    having
      count(t.time) < 2
    

    I prefer the first, because it is cleaner, more clear and can be expanded easier, despite the subselect.

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

Sidebar

Related Questions

I'm currently working on a database with the following requirements: There are accounts of
Case Currently I'm working on database seeding script, executed with sqlcmd . For example
So I'm currently working on a Berkeley database through C, and I ran into
I’m currently working on a classic ASP project talking to an Oracle database. I’m
I'm currently working on a PHP application that uses a MySQL database for its
I am currently working on a solution in C# to copy database tables across
I'm working currently on a long polling script where i've to check a database
I am trying to make the open_id_authentication plugin working. Initially was doing it with
I'm currently working on someone else's database where the primary keys are generated via
Summary We have an ASP.NET application that allows users to query a SQL Server

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.