'Is it possible to select a variable of an outer query from a subquery?
Basically, I'm trying to reference the row currently being evaluated and use it in a subquery.
...
CASE WHEN [type] IN (1, 2) THEN (
SELECT companyName FROM Company
WHERE id = (SELECT companyId FROM [TransactionParty]
WHERE id = _this.fromTransactionPartyId))
END AS senderCompanyName
...
Where "_this.fromTransactionPartyId" is referring to the fromtransactionPartyId column of the current row where [type] IN (1, 2). Is this possible?
Solution 1:[1]
That's not possible. Are you trying to fetch companyName from the Company table only when it has a respective entry in the TransactionParty table? In that case, you use inner join:
Select c.CompanyName from Company c inner join TransactionParty t on c.id = t.companyId and c.fromTransactionPartyId=t.id
Solution 2:[2]
That's perfectly possible. You just need to name your identifiers correctly with the correct table like tab1.Id:
select
case when id in (1,2) then (SELECT value FROM tab2
WHERE tab2.id = (SELECT id2 FROM idreltab
WHERE id1 = tab1.Id))
else 'not in (1, 2)' end
from tab1
(I replaced your table names with tab1[unknown], tab2[Company] and IdRelTab[TransactionParty])
See this fiddle as example (in oracle, as you didn't mention a DBMS)
However, I'd try to use joins instead of subqueries as they're far more performance friendly
Solution 3:[3]
I have come across WolfSSL benchmarks several time for the purpose of comparing cryptography speed on different hardware.
They do not seem to provide data for a 16MHz micro controller, but they list a 48MHz Atmel SAMD21 based on an ARM Cortex M0 with a speed of 0.138MB/s for AES.
In comparison, an Intel(R) Core(TM) i5-6300U @ 2.4GHz is listed with a speed of 15.911 MB/s for AES-GCM.
One limitation of these benchmarks is that comparing them strictly is not possible: not much details on how they ran it (bare CPU versus "regular PC"), not always the same data provided (AES (?) for one, AES-GCM for the other).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Muhand Jumah |
| Solution 2 | Chrá´‰z remembers Monica |
| Solution 3 | Lou_is |
