0

I have three tables TableA, TableB and TableC. TableA has the following columns

    MyId
    IsFound

I want to update Table.IsFound to Yes or No based on the below result.

SELECT t1.MyId FROM  TableA t1 WHERE t1.MyId IN (
SELECT     t2.Id FROM
 TableB t2, TableC t3
 WHERE t2.Value1 = t3.Value1 AND t2.Value1 !='XXXX' AND  t3.Value1 !='XXXX');

Expected logic:

If t1.MyId is not null
  Update TableA.IsFound ="Yes"
Else
  Update TableA.IsFound ="No"
End If

Thanks for your help. I couldn't find the solution because of my basic SQL knowledge.

aka baka
  • 213
  • 2
  • 10
  • What you have currently is not a proper subquery. `UPDATE` requires you to select a table, column, and value to set it to. This is no exception in a subquery. Also note that double quotes make the engine look for a column with that name rather than taking the literal value. It should look more like `UPDATE TableA SET IsFound = 'Yes'`. – Jesse Aug 29 '22 at 22:42
  • I want to incoprate Update statement with my sql – aka baka Aug 29 '22 at 22:44
  • And I just told you how to. – Jesse Aug 29 '22 at 22:47
  • Thanks, I got it and found the solution – aka baka Aug 29 '22 at 23:04
  • @Jesse , _" double quotes make the engine look for a column with that name rather than taking the literal value"_ ? This is not true in MySQL [refer this](https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=2500eb136dd06d11a019436d8fcfc12a) – FanoFN Aug 29 '22 at 23:49

0 Answers0