0

From table

Name | Zone
AAA    1
BBB    2
CCC    3
DDD    1
...    ...

I want to get Name of Zone=1 and Zone=2 each at once.

I used two select clauses before, like

SELECT Name FROM ... WHERE ZONE=1
SELECT Name FROM ... WHERE ZONE=2

But above query searches the ZONE column twice.

I want to find it at once because my table has actually >100million rows

How can I get result like below by at once(least cost)?

Zone=1 | Zone=2
AAA      BBB
DDD      NULL
안유빈
  • 33
  • 5
  • Does this answer your question? [How can I return pivot table output in MySQL?](https://stackoverflow.com/questions/7674786/how-can-i-return-pivot-table-output-in-mysql) – T.S. Dec 02 '20 at 01:47

1 Answers1

0

How about in?

select zone, name
from t
where zone in (1, 2);
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786