Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - SQL Help
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

SQL Help

 Post Reply Post Reply
Author
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Topic: SQL Help
    Posted: 17 March 2005 at 6:02pm
Hi

Could anyone help me with a query?

tblUsers
  ID
  teamID

tblSectorUsers
  userID
  sectorID

I need to return a count(*) from tblSector users:

WHERE sectorID = x

And where the user whos user ID the record relates to has a teamID of y.

Any help appreciated!
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 17 March 2005 at 6:07pm
"Select Count(SectorID) as Count FROM tblSectorUsers WHERE tblSectorUsers .SectorID = x AND (tblSectorUsers .UserID = tblUsers.TeamID AND tblUsers.teamID=y)"

i think that will help

not sure it'll work but thats the idea

you dont need the brackets


Edited by dj air - 17 March 2005 at 6:08pm
Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 17 March 2005 at 6:40pm
Thanks for that, doesn't seem to work though.  I could go for the other option of opening all returned user records and checking the team but that would be resource intensive, or I could store teamID in sectorUsers but that'd just be data duplication.
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 17 March 2005 at 6:44pm
what problem was you getting .. you can try

"Select Count(SectorID) as Count FROM tblSectorUsers WHERE tblSectorUsers .SectorID = x AND tblUsers.teamID=y AND tblSectorUsers .UserID = tblUsers.ID;"

was it the ID value from users is the same as UserID in sectorUser, if so then the above should be ok
Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 17 March 2005 at 7:02pm
Thanks for your help!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.