Solved

Firebird Subquery

Posted on 2008-10-14
4
920 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
ID: 22718863
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
ID: 22719072
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
ID: 22719329
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
ID: 23119165
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS Access question 11 59
oracle report printing 2 pages in one page 2 58
SQL BACKUP - 2008 R2 8 63
SQL Query 34 82
Read about achieving the basic levels of HRIS security in the workplace.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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…

863 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

22 Experts available now in Live!

Get 1:1 Help Now