Current location: Hot Scripts Forums » Programming Languages » ASP » Select Two Tables At Once


Select Two Tables At Once

Reply
  #1 (permalink)  
Old 06-26-05, 11:06 AM
Tesco Tesco is offline
ASP Guru
 
Join Date: Jun 2003
Location: UK
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Select Two Tables At Once

Back again,
This time, I'm selecting data from two tables at once. My SQL query is working fine, but my problem is, I have columns in each table that have the same name, example:
table_1
column_1
column_2
table_2
column_1
column_2

What I want to know is, how can I reference to only the value of column_1 in table_1 and not column_1 in both? I've tried something similar to:
<%=rsLa("table_1.column_1")%>
But I'm getting a error saying that the item cannot be found. If it's any help, my SQL query is below.

Code:
"SELECT * FROM tbl_Cars, tbl_Votes WHERE tbl_Cars.UserID = '" & Request.Cookies("JuicedTuning")("UserID") & "'"
Any Ideas?
ta
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-26-05, 09:50 PM
koncept
Guest
 
Posts: n/a
This is how i do it

the c and the v after each table is a alias that can be used to reference it.

"SELECT * FROM tbl_Cars c, tbl_Votes v WHERE c.UserID = '" & Request.Cookies("JuicedTuning")("UserID") & "'"

then to output,

response.write(rs("c.col1")) cars or response.write(rs("v.col1")) if you wanted the votes

hope that makes some sense

edit: i see no actual errors with your code though.... & first line changed
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-27-05, 07:31 AM
Tesco Tesco is offline
ASP Guru
 
Join Date: Jun 2003
Location: UK
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks koncept, but as soon as I reference to one of them, I'm still getting a error:
Item cannot be found in the collection corresponding to the requested name or ordinal.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 06-27-05, 08:52 AM
koncept
Guest
 
Posts: n/a
silly me, i forgot to link the tables

what it is doing now is creating a cartesian product (garbage) it is listing everything as one big table with all the columns together

this where statement links the two tables and allows you to work with them the way you want
where c.id=v.id and....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Select results from 2 tables Mortal_Takeda PHP 6 05-13-05 08:28 AM
Multiple Select phppick JavaScript 3 04-11-05 01:09 AM
Select List insert into DB The Omega JavaScript 1 01-12-05 01:51 PM
select from 2 tables?.. kasper PHP 3 07-09-04 07:34 AM
i have 3 select box this is urgent traceMe JavaScript 0 12-02-03 02:24 AM


All times are GMT -5. The time now is 10:25 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.