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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Determining number of unique values

Author  Topic 

paintstripper
Starting Member

3 Posts

Posted - 2006-10-21 : 04:41:18
I have two tables, owner and property_.
Here are the two create statements for these tables,

--OWNER TABLE				--3
create table owner
(owner_num SMALLINT PRIMARY KEY NOT NULL,
first_name VARCHAR(20),
last_name VARCHAR(20),
street VARCHAR(30),
city_town VARCHAR(20),
postcode VARCHAR(4),
phone_num VARCHAR(20));


--PROPERTY TABLE --4
create table property_
(property_num SMALLINT PRIMARY KEY NOT NULL,
staff_no INT,
street_no VARCHAR(15),
street VARCHAR(30),
postcode VARCHAR(4),
property_type VARCHAR(30),
no_of_bedrooms TINYINT,
no_of_bathrooms TINYINT,
property_state VARCHAR(20),
tenant_limit Int,
owner_num SMALLINT,
CONSTRAINT staff FOREIGN KEY (staff_no) REFERENCES real_estate_agent(staff_num),
CONSTRAINT ownern FOREIGN KEY (owner_num) REFERENCES owner(owner_num));


I need to know how to display all owners that own two properties or less. Any help is appreciated.
Thanks, Dan

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-10-21 : 06:37:39
[code]select owner_num
from owner o inner join property p
on o.owner_num = p.owner_num
group by owner_num
having count(*) <= 2
[/code]


KH

Go to Top of Page
   

- Advertisement -