I try to perform the following query, but it seems to get stuck, and the MySQL server eats up all the CPU.
Can anyone see what the problem is:
select count(people.ID) from people where people.ID in (SELECT people.ID FROM people, event WHERE (people.ID = event.Owner AND event.Place like '%sh%' AND event.Type IN ('Birthday', 'Wedding')));
The ID is the key of the people table.
Here is the definition of the event table:
CREATE TABLE event (
ID INT UNSIGNED NOT NULL,
Owner INT UNSIGNED NOT NULL,
Type VARCHAR(100) default '',
Place VARCHAR(255) default '',
PRIMARY KEY (ID),
FOREIGN KEY Belongs_to_fk (Owner) REFERENCES people(ID)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Here is the definition of the people table
CREATE TABLE people (
ID INT UNSIGNED NOT NULL,
PRIMARY KEY (ID),
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
The people table has more columns, but they should not be relevant.
Note: the inner query works perfectly when it's on its own.
Thanks