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
 Select statement

Author  Topic 

mlawton40
Starting Member

15 Posts

Posted - 2008-02-19 : 06:02:39
Hey,

I have the following 2 tables with the following fields:

Postcode
Postcode
Town

Courses
Town

I have a textbox which accepts a Postcode and then a submit button. When the submit button is clicked I want to:
SELECT * from Courses WHERE the postcode entered matches postcode from the table Postcode and therefor selects the town from postcode to be able to select the results from Courses.

Hope this makes sense, if not then let me know, i can probably word it better. I'll keep trying, any help would be great!

Cheers, Mark

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-02-19 : 06:07:03
[code]Select *
from courses c join PostCode pc
on c.town = pc.town
where <some-condition>[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2008-02-19 : 06:12:22
I think this is what you're looking for . Where are the results held?

CREATE TABLE #postcode
(postcode VARCHAR (20),
town VARCHAR(20)
)

CREATE TABLE #courses
(town VARCHAR (20),
course VARCHAR(20)
)




INSERT INTO #postcode
SELECT 'BN1','London'
UNION
SELECT 'BN2','Brighton'


INSERT INTO #courses
SELECT 'London','SQL'
UNION
SELECT 'Brighton','DTS'

SELECT c.course,c.town FROM #courses as c
INNER JOIN #postcode as p ON c.town = p.town
WHERE p.postcode = 'BN1'

DROP TABLE #postcode
DROP TABLE #courses

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page
   

- Advertisement -