Solved

Firebird Subquery

Posted on 2008-10-14
4
915 Views
Last Modified: 2013-12-09
Good day

I would like to know how can I do the following subquery.

I have two tables and my data looks like this

Table A
Suite  [PK]
Week [PK]
RoomStatus

Table B
Suite  [FK]
Week [FK]
HomeRoom

example of data in table A
Suite    Week    RoomStatus
A         1           OPEN
B         2           OPEN
C         3           CLOSE


Example of data in table B

Suite  Week     HomeRoom
A       1            A
B       1            C
C       1            B

Now in my select I want to select everything from table B, but I want to get for each row the person actual RoomStatus from table a.

for example row 1 in table B, the guest HomeRoom  = the Suite where he is currently in,
but row two The guest are in Room B but his HomeRoom is C ( I need now in this select his RoomStatus from table a)

If possible I want to use a subquery to perform this select because I need to perform a lot of additional sql once I got the data.

Thank you
Henry
0
Comment
Question by:henryreynolds
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
NickUpson earned 125 total points
Comment Utility
I believe this will be easier to achieve with a stored procedure, then you can do the addditonal sql on the server as well

select b.Suite, b.Week, b.HomeRoom, a.roomstatus from tableb b join tablea a on b.homeroom = a.suite and b.week = a.week
0
 

Author Comment

by:henryreynolds
Comment Utility
Hi NickUpson

I already have it in a store procedure to do the additional sql, the idea of yours wont work 100% because there could be rooms empty or in maintenance and then they dont have a homeroom.

thanx

henry
0
 
LVL 19

Expert Comment

by:NickUpson
Comment Utility
so if they have a homeroom you want the status for that, if they don't you want what? (null, status of room they are in, something else)
0
 
LVL 40

Assisted Solution

by:Sharath
Sharath earned 125 total points
Comment Utility
check this
select b.Suite, b.Week, b.HomeRoom, a.roomstatus from tableb b left join tablea a on b.homeroom = a.suite and b.week = a.week

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now