sql join in asp using record sets
I need to make a join in my sql for my asp website, but im not sure how to select two tables in the database. This is what i have
Dim ORSp
Dim products
Dim sqltext
ID=Request.QueryString("title")
Set ORSp=server.createobject("ADODB.Connection")
ORSp.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("20509703.mdb")
<strong>Set products = Server.CreateObject("ADODB.Recordset")</strong>
sqltext="Select catagories.cat_ID, catagories.Title as c"
sqltext=sqltext & "products.product_ID, products.cat_ID, products.Title, products.Description as p"
sqltext=sqltext & "from catagories c, products p"
sqltext=sqltext & "where c.cat_ID=p.cat_ID AND c.Title=" &title& ";"
products.Open sqltext, ORSp
the part in bold is where im getting confused because it only selects one table how can i select two tables?
JeevesBond posted this at 06:40 — 3rd January 2007.
He has: 3,956 posts
Joined: Jun 2002
It seems like you are selecting two tables, obviously the recordset returned will be the result of merging the two tables.
Does this code not work? The only things that seem wrong are [incode]catagories.Title as c[/incode] and [incode]products.Description as p[/incode]. I believe you need to remove the 'as c' and 'as p' parts as you repeat this later on with table instead of fields ([incode]from catagories c, products p[/incode]).
If the code doesn't run, could you post what the error is? If you're just unsure of what to do with that recordset then let us know what you're trying to do and maybe we can point you in the right direction.
a Padded Cell our articles site!
benf posted this at 16:44 — 3rd January 2007.
They have: 426 posts
Joined: Feb 2005
i fixed it i was being stupid really all i needed to do was
select * from products where catagory ="&ID
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.