Solved

Firebird Subquery

Posted on 2008-10-14
4
929 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 41

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

 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

Question has a verified solution.

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

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
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…

615 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