Re: SQL help

From: Date: Tue, 10 Apr 2001 10:30:56 +0000
Subject: Re: SQL help
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-8426@lists.php.net to get a copy of this message
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: renze@datalink.nl ** M: +31 6 218 111 43 ***************************

« previous php.db (#8426) next »