Sila Khatun Sila Khatun - 7 months ago 10
SQL Question

SQL Sub query Issue

Unable to catch Sub Query output on where

There is my SQL code

SELECT Txn.TrnID, Txn.Date, Txn.Amount,
(SELECT `MetaValue` FROM `meta` WHERE `Parent` = 'DB_Transaction' AND `MainID` = Txn.TrnID AND `MetaKey` = 'SalesID' AND `MetaValue` = '803') AS SubqueryResult
FROM transaction as Txn
WHERE SubqueryResult = '803'
LIMIT 10


I'm getting this error


Unknown column 'SubqueryResult' in 'where clause'

Answer

May you can try Dr. Stitch. which is

SELECT Txn.TrnID, Txn.Date, Txn.Amount, m.MetaValue FROM transaction as Txn inner join meta as m    on m.Parent = 'DB_Transaction' and m.MainID = Txn.TrnID AND m.MetaKey = 'SalesID' AND m.MetaValue = '803' LIMIT 10
Comments