1

If I have a set of strings, what SQL statement would determine which of those strings are found in one column of a table?

I would want it to return which strings are found, or Null if none are found.

CJ7
  • 22,579
  • 65
  • 193
  • 321
  • You have a "set". A table? In another program? A comma delimited list? Also please always state RDBMS when tagging something with SQL, SQL is just a language with multiple implementations. Each has unique ways of solving a problem – Ben Aug 18 '12 at 08:43
  • @Ben: ANSI-89 Level 1 please. The set of strings can be represented any way you want. Comma-delimited list is fine. – CJ7 Aug 18 '12 at 08:44
  • The SQL-2003 defines window functions, which are unsupported by MySQL, as part of the ANSI standard... if you want a RDBMS agnostic solution by all means specify but my point still stands; if it's going to be run against a specific RDBMS it's better to state it. – Ben Aug 18 '12 at 08:49
  • @Ben: ANSI-89 is what I need. – CJ7 Aug 18 '12 at 08:52
  • @habibzare: no, I need to search over one column of the table – CJ7 Aug 18 '12 at 08:53
  • -1 badly written unclear question. The answer you give doesn't answer the question you asked. To find columns **contain** ing the string you would need `LIKE %...%` – Martin Smith Aug 18 '12 at 10:17

1 Answers1

2
SELECT DISTINCT Column1 FROM Table1 WHERE Column1 IN ("String1","String2","String3")
CJ7
  • 22,579
  • 65
  • 193
  • 321
  • "which strings are found, or Null if none are found": may want to add a DISTINCT on that, and also be aware that this will not return NULL if no strings are found; it will return the Null (Empty) set. – Andy Aug 18 '12 at 09:16