Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Complete noob sql problem

Author  Topic 

mpooley
Starting Member

13 Posts

Posted - 2010-09-16 : 11:36:32
sqlserver express
I need help please.

I have 5 tables 'Room' 'roomsensor' 'reading' 'sensor' and 'zone'

columns

room has ID Title and Zone
Roomsensor has ID roomID and sensorID
reading has ID Temperature roomsensorID readingDate and BoilerState
sensor has ID Title and Offset
zone has ID and Title

one query has me stumped as it's returning multiple copies of the same data

I have a stored procedure with roomID , startdate and endate parameters

and a simpler one with no params both give multiples

this is the simpler one


SELECT r.ID, r.Temperature, r.ReadingDate, rm.Title AS 'RoomName', r.BoilerState

FROM Reading r JOIN RoomSensor rs
ON r.RoomSensorID = rs.ID
JOIN Room rm ON rs.RoomID = rm.ID


ORDER BY r.ReadingDate ASC


could anybody have a look and tell me what I am doing wrong please?


Mike


Michael D Pooley

rohitvishwakarma
Posting Yak Master

232 Posts

Posted - 2010-09-16 : 11:43:03
You are having multiple readings for a RoomSensor in Reading table.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-09-16 : 11:44:33
It is about your data.
When you are joining tables and in one table there multiple rows for a joining condition then the select gives multiple rows in the result.
That's normal.

Since I don't know anything about your data in the tables this all I can say.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -