[Phpwm] SQL Problem

Andy Cowan andyc at waverider.net.uk
Thu Apr 3 16:06:20 BST 2008


Try

Select * from companies where company_id not in (select distinct company_id from todos) and company_id not in (select distinct...) etc.

Haven't tried it, but it should work.

YMMV etc.

A.

Andy Cowan
OpenSense Ltd


From: phpwm-bounces at mailman.lug.org.uk [mailto:phpwm-bounces at mailman.lug.org.uk] On Behalf Of Daniel Davies
Sent: 03 April 2008 15:58
To: West Midlands PHP User Group
Subject: [Phpwm] SQL Problem

Hello all,

Sorry, this is not strictly PHP, but its all the same kettle of fish.

I'm working on a system that has companies, and these companies can have activities and todos, defined something like:

companies { company_id, name, etc... }
todos { todo_id, company_id, etc... }
activities { activity_id, company_id, etc... }

I'm trying to write a query which will only return companies that do NOT have an activity or a todo in one query - my mind is blank! Maybe my brain has been rotted by this system, but I can't think of a nice simple way to do it. Any ideas? I've had some thoughts about using count, but I'd like to check I'm not missing a simple solution before I start writing elaborate queries.

Regards,

Daniel

________________________________
Wave Rider Internet is a trading style of OpenSense Ltd.
Registered in England and Wales No 04999653
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.lug.org.uk/pipermail/phpwm/attachments/20080403/9f014bbd/attachment.html


More information about the Phpwm mailing list