General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 8th, 2006, 10:35 AM
Jhodas Jhodas is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 2 Jhodas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 24 sec
Reputation Power: 0
SQL count, condition from seperate table

select contact1.key1, contact2.umksalreg count(umksalreg) from contact1, contact2 where contact1.key1 = 'purchaser' and contact1.accountno=contact2.accountno group by contact2.umksalreg

Hopefully you get what I'm trying to do. I keep getting an incorrect syntax error.

I'm counting the number of entries with 'purchaser' in the key1 column in the contact1 table, and grouping them by umksalreg which resides in the contact2 table. I'm a relative SQL newbie, and feel kind of out of my depth. please be gentle!

Jho.

Reply With Quote
  #2  
Old August 14th, 2006, 06:23 AM
Jhodas Jhodas is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 2 Jhodas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 24 sec
Reputation Power: 0
Well I figured it out in the end, not sure if I'm using good SQL practise, but it gives and accurate count and doesn't give any errors.

For anyone else who wants to know how, the code is below. I used a left join, and our database frontend decided to throw the 'nolock' in.

Code:
SELECT COUNT(*) AS NUMBER, UMKSALREG FROM 
CONTACT1 LEFT JOIN CONTACT2 WITH (NOLOCK) ON 
(CONTACT1.ACCOUNTNO=CONTACT2.ACCOUNTNO) WHERE 
CONTACT1.KEY1='PURCHASER' GROUP BY 
CONTACT2.UMKSALREG

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > SQL count, condition from seperate table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT