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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:02:23+00:00 2026-06-01T04:02:23+00:00

I have 2 tables, let says the first table named Schedule and the second

  • 0

I have 2 tables, let says the first table named “Schedule” and the second named “Setting”.

TABLE “SCHEDULE”

 ID    Name    StartTime    EndTime     Room  
---------------------------------------------
 111   AAAA    08:00        09:00       -
 112   BBBB    08:00        09:00       -
 113   CCCC    08:00        09:00       -
 114   DDDD    08:30        09:30       -
 115   EEEE    08:30        09:30       -   
 116   FFFF    08:30        09:30       -      

TABLE “SETTING”

 ID    Type    Room  
------------------------
 111     1     BPD01  
 112     2     BPR33  
 113     2     BPR33  
 114     2     BPR35  
 115     2     BPR33  

I want to get the result like:

 Room    StartTime  EndTime  Total Used   
---------------------------------------
 BPR33   08:00      09:00    2           
 BPR33   08:30      09:30    1           
 BPR35   08:30      09:30    1               

I have the code like:

SELECT ST.Room, S.StartTime, S.EndTime, COUNT(*) AS [Total Used]
FROM Schedule AS S CROSS JOIN Setting AS ST
WHERE (ID IN
  (SELECT ID FROM Setting
   WHERE (Type = '2')))
GROUP BY ST.Room, S.StartTime, S.EndTime

But the code resulted in showing all of the record in Setting with the counted value, the filter does not run properly.

How to do that?

  • 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-01T04:02:25+00:00Added an answer on June 1, 2026 at 4:02 am

    I see a few potential issues here:

    • Your WHERE ID IN (SELECT ID FROM Setting WHERE Type='2') looks like it could just be WHERE Type='2'
    • What data type is your Type column? If it is INT, do WHERE Type = 2 as opposed to WHERE Type = '2' (which you’d use if Type was VARCHAR).
    • You do not appear to have a JOIN condition linking your two tables together (e.g. WHERE S.ID = ST.ID)

    All together now:

    SELECT ST.Room, S.StartTime, S.EndTime, COUNT(*) AS [Total Used]
    FROM Schedule AS S CROSS JOIN Setting AS ST
    WHERE S.ID = ST.ID 
    AND Type = 2
    GROUP BY ST.Room, S.StartTime, S.EndTime
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have 2 tables. The first table is a list of personas.
I have two tables with similar columns - let's say table A with column
Let's say you have the following two tables: X Table X_ID Y_ID_F X_Value 1
Let's says I have a set of tables that match the following scenario: Crates
Let's say I have two tables: Table A ProdID | PartNumber | Data... 1
I have a database with two tables - let's call them Foo and Bar.
The problem: let's say I have two tables Client , and Product , in
Let's say I have four tables: PAGE , USER , TAG , and PAGE-TAG
Let's say I have two tables: Report Comment And assuming I have a database
Scenario: Let's say I have two tables, TableA and TableB. TableB's primary key is

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.