开发者

SQL query to match multiple values to a field in select statement

I want to select distinct values of Column A where Column B = any members of a s开发者_如何学Pythonet S.

Is there a way to do this directly in SQL without looping and then filtering afterwards in code?

Thanks

EDIT: The set S is a PHP array. Does this make a difference?


Use the IN clause with a list of values, or a subquery (not sure if supported in MySql since I use Oracle). The match can be on more than one column.

SELECT column_a
  FROM mytable
 WHERE column_b IN (1, 2, 3)

SELECT column_a
  FROM mytable
 WHERE column_b IN (SELECT column_c FROM myothertable)


SELECT DISTINCT
    columnA
FROM
    yourTable
WHERE
    columnB IN ( 'your', 'set', 'of', 'values' )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜