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

The Archive Base Latest Questions

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

SQL server 2008 Hello here is my query which returns the result SELECT *

  • 0

SQL server 2008

Hello

here is my query which returns the result

SELECT * FROM Rooms
WHERE RoomID in 
(SELECT t1.RoomId FROM 
(Rooms t1 INNER JOIN 
(SELECT RoomID, SUM(quantity) AS QTY FROM Room_Item GROUP BY RoomID
HAVING SUM(Quantity) = 0) t2 ON t1.RoomID = t2.RoomID))

above written query will return me the roomid of the rooms which dosen’t have any items in it (quantity = 0),
but now i want to filter out the result by buildings,

i got the list of room for specific building as below

select roomid from rooms where buildingblockid in (select buidingblockid from buildingblock where buildigID = 1)

so my query will be

return the roomid from rooms table where allocated items are 0 and filter out room by building number = 1

tables structure is as below – ONLY ESSENTIAL FIELDS ARE SHOWN

rooms => roomid(PK), buildingblockID(FK), roomname
room_item => roomitemid(PK), roomid(FK), itemid(FK), quantity
item => itemid(PK), itemname
buildingblock => buildingblockid(PK), buildingID(FK)
building => buildingID(PK), buildingName
  • 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:01:09+00:00Added an answer on May 31, 2026 at 11:01 pm

    You could create derived table to find rooms having no items, and join it to buildingWiseRoom to filter building one.

    select buildingWiseRoom.roomID
    from buildingWiseRoom
    inner join
    (
       select RoomID
         from Room_Item 
        group by RoomID 
       having SUM(Quantity) = 0
    ) itemlessRooms
      on buildingWiseRoom.roomID = itemlessRooms.roomID
    where buildingWiseRoom.buildingID = 1
    

    UPDATE as table structure changed:

    select rooms.roomID
    from rooms
    inner join buildingblock 
       on rooms.buildingblockID = buildingblock.buildingblockID
    inner join
    (
       select RoomID
         from Room_Item 
        group by RoomID 
       having SUM(Quantity) = 0
    ) itemlessRooms
      on rooms.roomID = itemlessRooms.roomID
    where buildingblock.buildingID = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In sql server 2008, I have the following query: select c.title as categorytitle, s.title
SQL Server 2008. I have this very large query which has a high cost
SQL server 2008 on WINDOWS 2008 Please compare following sqls: 1. select count(*) from
SQL Server 2008: I've got a situation here in which I wish to read
Hello all I am using MS SQL Server 2008 R2 and needed some help
Hello I'm doing some data conversion from PostgreSQL to Microsoft SQL Server. So far
In SQL Server 2008. I need execute a query like that: DECLARE @x AS
Hello I am working on a SQL database Using Microsoft SQL server 2008 R2
Using SQL Server 2008. I have a stored proc which has start and end
On SQL Server 2008 R2, I have following T-SQL code: SELECT CAST(GETDATE() AS DATETIMEOFFSET);

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.