-2

I have tried this query:

SELECT `wh_pengeluaran`.`Nomor Dokumen`, `wh_pengeluaran`.`Created 
Date`, `inventory transactions`.`Transaction Item`,(SELECT Quantity 
FROM `inventory transactions` WHERE `inventory transactions`.`Proforma 
Invoice` > 0) as qtykeluar
FROM `inventory transactions` JOIN `wh_pengeluaran`
WHERE `inventory transactions`.`Transaction Item` = 1

But MySQL said: Documentation

1242 - Subquery returns more than 1 row

Anyone help, please.. What's wrong with the syntax? I've no idea Thank you! :)

Community
  • 1
  • 1
  • hi Metta, welcome to stackoverflow, as the error said, the subquery (your `SELECT Quantity FROM... as qtykeluar`) returns more than one result, so mysql dont know what to do to put multiple items into single column. what are you trying to achieve with the query if we may know? fyi, you can use [LIMIT](https://www.w3schools.com/php/php_mysql_select_limit.asp) if you dont care about the rest of the result of the subquery though. – Bagus Tesa Jan 23 '20 at 03:37
  • 2
    Does this answer your question? [#1242 - Subquery returns more than 1 row - mysql](https://stackoverflow.com/questions/12597620/1242-subquery-returns-more-than-1-row-mysql) – Thomas F Jan 23 '20 at 03:48

1 Answers1

0

The problem is subquery returning more than one row which is not possible if you are using the same with a select statement. MySql doesn't know what to put from multiple items into single column.

I don't know what exactly you want to achieve but probably you can select only one record in subquery using LIMIT 1 if you don't care about all records of subquery and want to select any one.

Your subquery should be something like below:

SELECT Quantity 
FROM `inventory transactions` WHERE `inventory transactions`.`Proforma 
Invoice` > 0 LIMIT 1

Full query:

SELECT `wh_pengeluaran`.`Nomor Dokumen`, `wh_pengeluaran`.`Created 
Date`, `inventory transactions`.`Transaction Item`,(SELECT Quantity 
FROM `inventory transactions` WHERE `inventory transactions`.`Proforma 
Invoice` > 0 LIMIT 1) as qtykeluar
FROM `inventory transactions` JOIN `wh_pengeluaran`
WHERE `inventory transactions`.`Transaction Item` = 1
Mayur Patel
  • 1,741
  • 15
  • 32