1

I want to retrieve First and Last Row using client_id from my table. So I wrote this which threw an error (1241), Can Anyone please tell me what this issue with this code :

SELECT * 
FROM invoices 
WHERE invoice_id IN (SELECT  MAX(invoice_id), 
                             MIN(invoice_id) 
                     FROM invoices
                     );

WHERE AS this code is perfectly fine :

SELECT * 
FROM invoices 
WHERE invoice_id IN (SELECT  MIN(invoice_id) 
                     FROM invoices 
                     UNION SELECT MAX(invoice_id) 
                     FROM invoices
                    );

1 Answer 1

1

So I wrote this which threw an error (1241), Can Anyone please tell me what this issue with this code :

The error MySQL error 1241: Operand should contain 1 column(s) occurred because the following query

SELECT  MAX(invoice_id), MIN(invoice_id) FROM invoices  

returns two columns, not two values. In the where condition you have one column declared WHERE invoice_id IN.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.