I am trying to execute the following statement:
DELETE a
FROM db.table1 a
INNER JOIN (SELECT domainname
FROM db.table1
WHERE domainname LIKE '%.uci.edu'
GROUP BY keyvalue
HAVING COUNT(1) > 1
) b ON a.id = b.id
I got the error mentioned in my title. What I'm trying to achieve has been explained here: How to make the result of one query be in the NOT IN clause?
Please, help me to do this task. Why b.id is unknown ?? I have no experience in such type of Join. I understand joining two different tables, but for this statement can anybody explain please ? Please, note that the domainname
is unique value. The primary key is the id
and it is auto_increment but I don't use it to differentiate between columns. I mainly use another value domainname_no
which is unique.
EDIT: THE command above does not work.
what I need is the following : I have a list of domain names. say: aa.yahoo.com, bb.yahoo.com, cc.yahoo.com, aa.msn.com. Each domain name has a key value. If the key is shared, I want to delete this record. So, I selected the distinct values grouped them by the key value. If the record in not in the distinct set, and have the same top level domain, then I don't need it.
Example: My table: cert_id | domainname | domain_certificate | key 1 | a.yahoo.com | a.yahoo.com_1 |5555 2 | a.yahoo.com | a.yahoo.com_2 |6666 3 | b.yahoo.com | b.yahoo.com_1 |5555 4 | b.yahoo.com | c.yahoo.com_2 |6666
each domain might have more than one certificate associated with key. If one or more certificate with different domain name have the same key, I want to delete it.
Now, I have two domain names which are a.yahoo.com
and b.yahoo.com
have the same key. I need to delete b.yahoo.com
and any domain name that have the same pattern like '%.yahoo.com' and not equal to a.yahoo.com
which is the distinct value.
Currently, what I'm doing is quering the distinct values:
select distinct domainname
from db.table1
where domainname like '%.uci.edu'
group by keyvalue
order by domainname
Then delete any value that is not in the distinct list and have the same pattern %.yahoo.com
delete from db.table1 where domain not in ( I type the list of distinct domain
names manually)
and domainanme like '%.yahoo.com';
i hope the problem is clear now.
But this command does not work. For details see: How to make the result of one query be in the NOT IN clause?