I have a statement like this:
select lastname,firstname,email,floorid
from employee
where locationid=1
and (statusid=1 or statusid=3)
order by floorid,lastname,firstname,email
The problem is the column floorid. The result of this query is showing the id of the floors.
There is this table called floor (has like 30 rows), which has columns id and floornumber. The floorid (in above statement) values match the id of the table floor.
I want the above query to switch the floorid values into the associated values of the floornumber column in the floor table.
Can anyone show me how to do this please? I am using Microsoft sql server 2008 r2.
I am new to sql and I need a clear and understandable method if possible.
join
s. The strength in databases isn't in storing data, it's being able to create related data that you can then retrieve. In order to retrieve related data, youjoin
on whatever columns/criteria you want. This is one of the fundamental aspects of the RDBMS (R = Relational) so it's really just a matter of becoming familiar with the tools available to you (I'd recommend reading some tutorials online, possibly a book or two).