Skip to content
Advertisement

How to return T2 name based on data from T1?

T1 game

T2 heroes

T1 IDC = ID from T2

I need to return all heroes that have anything except null in POWER or in HP with LTIME != -1

Query should return ID and NAME from T2 for that heroes.

In this example query should return: 236 MAX

I tried this:

Advertisement

Answer

Your WHERE condition in the subquery is not correct. 0 is not the same thing as NULL. And POWER or HP != 0 is not the way you test both columns. You have to write POWER IS NOT NULL AND HP IS NOT NULL.

There’s no LTIME column in the heroes table, so you can’t test that in the main query. The subquery should return IDs, you can test that. But it’s generally better to use JOIN instead of IN.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement