Tag Archives: 1242

About MySQL error: subquery returns more than 1 row

Report: SQLSTATE[21000]: Cardinality cheesecake: 1242 Subquery returns more than 1 row
error means that the sub-query results are less than one row. The error is as follows:

Select * from table1 where table1. Colums =(select columns from table2); Take this SQL statement as an example.

1) if you are writing duplicates, remove the duplicates. When writing, you can add a logical decision (PHP) or a foreign key (mysql) to prevent the data from being written repeatedly.
(in my actual development, I encountered the situation of repeatedly writing data, I found the same two data in the database, which is not consistent with the original business requirements)
2) add limit 1 in the sub-query condition statement, find a qualified one can be
select * from table1 where table1. Colums =(select columns from table2 limit 1);