Home > Software engineering >  Error Code: 1242. Subquery returns more than 1 row: for carretera Glength
Error Code: 1242. Subquery returns more than 1 row: for carretera Glength

Time:09-13

SELECT c1.matricula, GLength(c1.geometry) as longitud 
FROM carreteras c1
WHERE GLength(c1.geometry) = (
    SELECT GLength(c2.geometry) 
    FROM carreteras c2
);

CodePudding user response:

When the subquery returns more than one row, you have to use IN:

SELECT c1.matricula, GLength(c1.geometry) as longitude
FROM carreteras c1
WHERE GLength(c1.geometry) IN (
    SELECT GLength(c2.geometry)
    FROM carreteras c2
);

or ANY:

SELECT c1.matricula, GLength(c1.geometry) as longitude
FROM carreteras c1
WHERE GLength(c1.geometry) = ANY (
    SELECT GLength(c2.geometry)
    FROM carreteras c2
);
  • Related