Help us understand the problem. What is going on with this article?

備忘録:SQLのINを複数列指定で使う

More than 5 years have passed since last update.

1:1 (列の数:条件の数)

列名=値で条件を指定
特定の値を持つ行を検索したい場合

select
    *
from
    table t
where
    t.col = "data";

普通。

1:n

列名 in (値...)
複数の値に一致する行を検索したい場合

select
    *
from
    table t
where
    t.col in ("data1", "data2");

あるいはorでつなげる。
割りと普通。
※INの中身が多くてSQLが長くてだめとかいうやつもいる

n:n

(列名, 列名, ...) in (値, 値, ... )

select
    *
from
    table t
where
    (t.col1, t.col2) in (
        ("hoge", "fuga"),
        ("foo", "bar")
    )

あんま必要になる場面がないから記憶の砂漠に埋まる。

その他

結合条件はfrom句に、検索条件はwhere句に書くのが個人的に好きです。「fromに検索条件書いてもいいやろ!!」という反論は受け付けた後にスルーします。

どうでもいいですが、テーブル名の別名をつけるのに毎回悩むのですが皆様はどうやってつけてるんですかね?。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした