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)
 relationship help in query

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2005-01-28 : 02:43:54
I have a main table of entries
I have a separate table listing areas

Now I have a link table with the entry id and area id (as each entry has more then one area)

How can I run a query searching all the entries for a specific area?

what is my relationships on those 3 tables?

Am I going about this in the wrong way?

nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-28 : 02:50:18
select e.*
from entries e
join entry_area ae
on e.entry_id = ae.entry_id
join area a
on a area_id = ae.entrty_id
where a.name = @myarea

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2005-01-28 : 03:15:35
select fp.*
from fundprograms fp
join fundarealinks ae
on fp.id = ae.fundprogramid
join areaofinterest a
on a id = ae.areaofinterestid

the above is returning an error


let me give you the complete structure as I am doing something wrong

4 tables

1. fundprograms - id,geographyid,name,deadline,comments
2. fundareallinks - id,areaofinterestid,fundprogramid
3. areasofinterst - id, areaeng
4. geographic-- id, geo

I will need to do a complete query querying based on areaofinterst,deadline, and geographicid

Can you help me?
Go to Top of Page

polygonSQL
Starting Member

8 Posts

Posted - 2005-01-28 : 06:17:41
I am going to assume that the "id" in each table are supposed to match up



select *
from fundprograms FP
inner join fundarealinks FL on FP.id = FL.id
inner join areaofinterest AI on FP.id = AI.id



select * from end_user
where clue > 0
GO
( 0 rows returned )
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2005-01-28 : 06:43:11
fundarealinks has a fundprogramid and areaofinterestid meant to combine the two tables fundprograms and areaofinterest

I tried

select *
from fundprograms FP
inner join fundarealinks FL on FP.id = FL.fundprogramid
inner join areaofinterest AI on FL.areofinterestid = AI.id

but it is still giving me an syntax error. (This is in access)

Go to Top of Page

polygonSQL
Starting Member

8 Posts

Posted - 2005-01-28 : 06:56:33
I don't know anything about acess sorry.

select * from end_user
where clue > 0
GO
( 0 rows returned )
Go to Top of Page
   

- Advertisement -