I have two tables, one contains user account info the other contains active
sessions in a web app.  In the user account table I have a column that
contains each user's 'access level'.  I'm somewhat new to relational
databases and SQL, and though the following is working for me, I want to
find out if it is the best way to handle it.

Obviously, during the user's session it is often necessary to determine
their specific access level.  Right now I am doing it in this fashion...

The session table looks like this:

session_id int(10) primary key,
username varchar(16) 'this is the foreign key related the user table'
created datetime,
updated datetime

The user table looks like this:

username varchar(16) primary key,
password varchar(16),
firstname varchar(30),
lastname varchar(30),
email varchar(100),
access int(10)

So when I need to determine the access level of a user during a given
session I use the following query:

select user.access
   from user, session
   where session.session_id = '$id'
   and session.username = user.username;

This is working fine right now... but exactly how it is working and/or what
it is actually doing still confuses me a little bit.  The reason I did it
this way is because at any given time I know the $id (session id) variable.
It seemed more elegant to do it as a join rather than first grab the
username from the session table with a select statement, and then use the
username to grab the access level from the user table with another select
statement.

Is this a good looking query??  Or is there a better way to do this?
Thanks!

 - Ben


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to