简体   繁体   English

mySQL where in子句

[英]mySQL where in clause

Is it possible to do something like this with a where in clause, I am required to query the following data using where in. 是否可以使用where in子句进行类似的操作,我需要使用where in子句查询以下数据。

select *
FROM instructor AS i
INNER JOIN teaches AS t ON i.id = t.ID
where course_id in ('C%'); -I want every course ID that begins with C

Use LIKE : 使用LIKE

select *
FROM instructor AS i
INNER JOIN teaches AS t ON i.id = t.ID
where course_id LIKE 'C%';

使用LIKE代替IN完成。

Use like 'C%' . like 'C%'使用。

select * FROM instructor AS i INNER JOIN teaches AS t ON i.id = t.ID WHERE course_id LIKE 'C%';

See http://www.techonthenet.com/sql/like.php 参见http://www.techonthenet.com/sql/like.php

  1. I want every course ID that begins with C 我想要每个以C开头的课程ID

  2. Is there a way to accomplish this with WHERE IN? 有什么办法可以在WHERE IN做到这一点吗? That's what I am required to use. 这就是我需要使用的。 – FatalProphet –致命先知

You can compare the first letter of the data with desired letter. 您可以将数据的第一个字母与所需的字母进行比较。

Example : 范例

-- for other matchings too, input other comma separated letters
where LEFT( course_id, 1 ) in ( 'C' )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM