Here is what I am doing now, in mysql 4.x

This gives me a name/id list from a table
SELECT campaign_name, id
FROM campaigns
WHERE user_id = 123;


This will tell me which of the above name/id's are in use in another table.
SELECT distinct(campaign_id)
FROM addresses_incampaign
WHERE user_id = 123
ORDER BY campaign_id";

The reason I need to know which campaign_id's are used in the second table,
is to see if they are allowed to delete the record from campaigns, if there
are matching records in both tables, they are not allowed to delete.

Somehow, I am looking to get a single SQL query to give me a result with a
count as a int
Campaign_name       records_in addresses_incampaign
foo                 15
bar                 12
example             0   (safe to delete)
anohther            2

-- 
-------------------------------------------------------------
Scott Haneda                                Tel: 415.898.2602
http://www.newgeo.com                       Fax: 313.557.5052
[EMAIL PROTECTED]                            Novato, CA U.S.A.



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to