SQL
DELETE based on a JOIN condition
Submitted by madvip on Thu, 01/24/2008 - 12:45.You may wish to delete records in one table based on values in another table. Since you can't list more than one table in the FROM clause when you are performing a delete, you can use the EXISTS clause.
For example:
DELETE FROM suppliers
WHERE EXISTS
( select customers.name
from customers
where customers.customer_id = suppliers.supplier_id
and customers.customer_name = 'IBM' );
Calculating Percentage of Total in SQL
Submitted by madvip on Fri, 11/23/2007 - 10:20.Suppose we have the following table which consists of two columns - a user and his favorite album.
mysql> select * from albums_votes; +-----------+----------+ | user | album_id | +-----------+----------+ | 1000 | 2 | | 2000 | 3 | | 3000 | 1 | | 4000 | 3 | | 5000 | 3 | | 6000 | 3 | | 531514255 | 1 | | 686711159 | 2 | | 618496371 | 2 | | 705891065 | 2 | +-----------+----------+ 10 rows in set (0.00 sec)

