Russ Michell wrote:
> 
> Hi there folks, I have a small prob regarding SQL on MySQL 3.22.32
> using php4.0.3pl1 :
> 
> I want to select DISTINCT sports from one table WHERE a username and a
> password match a username and a password in another table - not sure
> how to construct my query.
> 
> In an ideal world it's gonna look something like this:
> 
> $sql = "SELECT DISTINCT sportID FROM $table_sport";
> $sql .= "SELECT * FROM $table_users WHERE $table_users.usrName='$admin_username'
> AND $table_users.usrPswd=password('$admin_password')";
> 
> Just not sure how the query needs to be constructed...
> Can anyone with even slightly advanced (over me) SQL knowledge help me
> out??
> 
> Many thanks!
> Russ
> 


Depends... Looking at what you posted it'll be something like this:

SELECT DISTINCT $table_sport.sportID
FROM $table_sport, $table_users
WHERE $table_users.usrName = '$admin_username'
AND $table_users.usrPswd = password($admin_password)
AND $table_sport.usrName = $table_users.usrName
AND $table_sport.usrPswd = $table_users.usrPswd

You can also make it a bit more readable, like this:

SELECT DISTINCT S.sportID
FROM    $table_sport S,
        $table_users U
WHERE   U.usrname = '$admin_username'
AND     U.usrPswd = password($admin_password)
AND     S.usrName = U.usrname
AND     S.usrPswd = U.usrPswd;

This way you don't have those variablenames in the query all the
time.
-- 

* R&zE:

***************************
**  Renze Munnik
**
**  E: [EMAIL PROTECTED]
**  M: +31 6 218 111 43
***************************

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to