Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error #1241 SQL Query

Tags:

sql

mysql

I keep getting error code #1241. I have been looking to find an answer but I can't find an answer that helped me.

Here is my code:

SELECT name, address, city, phone  
FROM customer
WHERE customer.ID IN (
    SELECT customer.ID, COUNT(*) AS amount_reservations 
    FROM customer, (
        SELECT ID 
        FROM customer, reservations 
        WHERE rent_time = 'weekend' AND 
        ID = customer_ID
    ) AS foo 
    WHERE customer.ID = foo.ID 
    GROUP BY customer.ID 
    HAVING amount_reservations > 1
)
like image 782
Willy Avatar asked Mar 20 '26 21:03

Willy


1 Answers

The subquery SELECT customer.ID, COUNT(*) AS amount_reservations should have a SINGLE column, not two.

Change it as:

SELECT name, address, city, phone  
  FROM customer  
  WHERE customer.ID IN (
    SELECT customer.ID
      FROM customer, (
        SELECT ID FROM customer, reservations 
          WHERE rent_time = 'weekend' AND ID = customer_ID
        ) AS foo 
      WHERE customer.ID = foo.ID 
      GROUP BY customer.ID HAVING count(*) > 1
    )
like image 180
The Impaler Avatar answered Mar 23 '26 11:03

The Impaler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!