Ask a Question related to ASP Database, Design and Development.
-
Ron #1
ASP / Access: use of same table twice in one query
Hi,
In a query I use the same table twice:
Select u.*, ud.*, dep.*, u2.*
from users as u, departments as dep, user_in_departments as ud, users as u2
where u.user_id = ud.ud_user_id
and dep.dep_code=ud.ud_dep_code
and u.user_manager=u2.user_id
and u.user_id = john1
I want to retrieve the data from the user and his manager, which are stored
in the same table.
When I try to retrieve this data, I am allowed to use fieldnames, but I ca
not include the tablename:
user = objRs("User_Name") is ok
usermanager = objRs("U2.User_id") is not ok, I can not use u2 to
define the tablename.
The data is stored in an Access database. Is this not possible in Access in
combination with ASP? Do I really have to specify the individual fieldnames
and name them in the select statement, i.e. Select u.user_id as userid,
u2.user_id as manageruserid?
Thx,
Ron
Ron Guest
-
Copy a table in Access structure only with CF query
Hello, I need to know how to create a new table by copying an existing table with the table structure only in a query Don't know the Syntax but... -
2 table query problem
Im having trouble with this query. I have 2 tables. I only want to display the events table but I want to sort the results based on the users... -
adding a hyperlink to a field in a table created from a d/b query (Access)
I've done this using Frontpage; and I know I've done it in the past using just ASP. I'm trying to stay away from FP on this site, so.... Can... -
Mulitple Table Query Help
I'm not sure the follow multiple table query is the right way to do what I need to do although it seems to be working: $php_SQL = "SELECT * ".... -
Temporary Table Query
Hi, I am inserting data into a temporary table using the following method: select a into #b from c This method works fine, but...if i... -
Bob Barrows [MVP] #2
Re: ASP / Access: use of same table twice in one query
That's right. You cannot use the table names. They are not part of the field
names supplied to ado. The solution is to use the good programming practice
of always explicitly naming the fields you want your query to return,
avoiding the use of selstar (select *).
Your query is returning too many columns. You have two user_id columns that
both contain the same data, etc. Why do you need to return both? It's a
waste of processing time and network traffic. By explicitly naming the
columns you wish to return, you avoid returning duplicate data, and you
improve performance by not requiring ado to make an extra trip to the
database to get the field names.
Oh! I see that you answered your own question below. Yes, you need to " ...
specify the individual fieldnames and name them in the select statement,
i.e. Select u.user_id as userid, u2.user_id as manageruserid."
HTH,
Bob Barrows
Ron wrote:<snip>> Hi,
>
> In a query I use the same table twice:
>
> Select u.*, ud.*, dep.*, u2.*-->
> When I try to retrieve this data, I am allowed to use fieldnames, but
> I ca not include the tablename:
>
> user = objRs("User_Name") is ok
> usermanager = objRs("U2.User_id") is not ok, I can not use u2 to
> define the tablename.
>
> The data is stored in an Access database. Is this not possible in
> Access in combination with ASP? Do I really have to specify the
> individual fieldnames and name them in the select statement, i.e.
> Select u.user_id as userid, u2.user_id as manageruserid?
>
> Thx,
> Ron
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Bob Barrows [MVP] Guest
-
Ron #3
Re: ASP / Access: use of same table twice in one query
Thx,
I needed the two user tables, because the data of the user and his manager
are in the same table and I need them both in one query.
I agree it is better to specify the fields I need in the select statement,
but as I needed it all...
Thanks for your fast reponse,
Kind regards,
Ron
"Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> schreef in bericht
news:O$E4UY%237DHA.3012@TK2MSFTNGP09.phx.gbl...field> That's right. You cannot use the table names. They are not part of thepractice> names supplied to ado. The solution is to use the good programmingthat> of always explicitly naming the fields you want your query to return,
> avoiding the use of selstar (select *).
>
> Your query is returning too many columns. You have two user_id columns....> both contain the same data, etc. Why do you need to return both? It's a
> waste of processing time and network traffic. By explicitly naming the
> columns you wish to return, you avoid returning duplicate data, and you
> improve performance by not requiring ado to make an extra trip to the
> database to get the field names.
>
> Oh! I see that you answered your own question below. Yes, you need to "> specify the individual fieldnames and name them in the select statement,
> i.e. Select u.user_id as userid, u2.user_id as manageruserid."
>
> HTH,
> Bob Barrows
>
> Ron wrote:> <snip>> > Hi,
> >
> > In a query I use the same table twice:
> >
> > Select u.*, ud.*, dep.*, u2.*>> >
> > When I try to retrieve this data, I am allowed to use fieldnames, but
> > I ca not include the tablename:
> >
> > user = objRs("User_Name") is ok
> > usermanager = objRs("U2.User_id") is not ok, I can not use u2 to
> > define the tablename.
> >
> > The data is stored in an Access database. Is this not possible in
> > Access in combination with ASP? Do I really have to specify the
> > individual fieldnames and name them in the select statement, i.e.
> > Select u.user_id as userid, u2.user_id as manageruserid?
> >
> > Thx,
> > Ron
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>
Ron Guest
-
Jeff Cochran #4
Re: ASP / Access: use of same table twice in one query
On Tue, 10 Feb 2004 15:45:12 +0100, "Ron" <r@xs.nl> wrote:
You really should be doing this anyway, as a good programming>Hi,
>
>In a query I use the same table twice:
>
>Select u.*, ud.*, dep.*, u2.*
> from users as u, departments as dep, user_in_departments as ud, users as u2
>where u.user_id = ud.ud_user_id
>and dep.dep_code=ud.ud_dep_code
>and u.user_manager=u2.user_id
>and u.user_id = john1
>
>I want to retrieve the data from the user and his manager, which are stored
>in the same table.
>
>When I try to retrieve this data, I am allowed to use fieldnames, but I ca
>not include the tablename:
>
>user = objRs("User_Name") is ok
>usermanager = objRs("U2.User_id") is not ok, I can not use u2 to
>define the tablename.
>
>The data is stored in an Access database. Is this not possible in Access in
>combination with ASP? Do I really have to specify the individual fieldnames
>and name them in the select statement, i.e. Select u.user_id as userid,
>u2.user_id as manageruserid?
practice. And yes, for this you need to specify the field names.
Though I suppose you could drop your result set into an array and use
that, but that's double work in programming and far worse than simply
using a proper query in the first place.
Jeff
Jeff Cochran Guest
-
Bob Barrows [MVP] #5
Re: ASP / Access: use of same table twice in one query
Ron wrote:
That's not what I said. I said your query was returning two user_id fields,> Thx,
> I needed the two user tables,
each containing the same data. Look: "u.user_id = ud.ud_user_id". These two
fields contain the same data, yet, due to your use of selstar, you're
returning both when only one is needed.
I understand that: I was not questioning that>because the data of the user and his
> manager are in the same table and I need them both in one query..
Don't get lazy ;-) You did not need them all ...> I agree it is better to specify the fields I need in the select
> statement, but as I needed it all...
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Bob Barrows [MVP] Guest



Reply With Quote

