Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL problem... extracting specific data 1

Status
Not open for further replies.

newphpbie

Programmer
Joined
Oct 17, 2003
Messages
110
Location
GB
Hi, I've been trying to make this work for most of the day now and I'm not getting very far....

I have 2 tables

User
intUserID
strFirstName
strLastName

Extension
intExtID
intExtNum
intUserID

I am trying to extract a list of users which don't have an Extension assigned to them. So....what I am trying to do is this...

Select All Users Which don't have an extry in the Extension Table.

I have been trying to do this using queries very similar to this.....

Code:
$userquery="SELECT strFirstName, strLastName FROM User WHERE intUserID NOT IN(SELECT * FROM Extension)";

but I'm getting no success....

Could someone advise me on this please or recommend somewhere I might find a tutorial on this....

Thanks.
 
Sorry, new here...
I'm running LAMP

Red Hat 8
Apache 1.3v
MYSQL Ver. 4.0
PHP 4.2.2
 
MySQL 4.0.x does not support subqueries ( so your clause "WHERE NOT IN(SELECT...)" won't work.

Typically, when trying to find records that are in one table but not in another, I use a left join:

SELECT
u.intUserID, u.strFirstName, u.strLastName
FROM
User u
LEFT JOIN
Extension e
ON
u.intUserID = e.intUserID
WHERE
e.intUserID is NULL;

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Fantastic, it's working fine. Thanks for the help and the link, much appriciated.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top