Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Firebird Subquery

Posted on 2008-10-14
4
Medium Priority
?
933 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 375 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 375 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this article, we’ll look at how to deploy ProxySQL.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

972 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