jeudi 21 mai 2015

SQL operator IN returns only DISTINCT

I have the following query:

SELECT class, subclass ,weight
FROM classes 
WHERE classes.term in ('this','paper','present','this','and','this','this') 

The above query returns only distinct values. For example I have the following table:

+-----------------------------------+
|class | subclass |  term  | weight |
+-----------------------------------+
|  a   |     b    |  this  |   1    |
+-----------------------------------+
|  c   |     d    |  paper |   1    |
+-----------------------------------+
|  e   |     f    |  sth   |   1    |
+-----------------------------------+

the result I will get is

+-----------------------------------+
|class | subclass |  term  | weight |
+-----------------------------------+
|  a   |     b    |  this  |   1    |
+-----------------------------------+
|  c   |     d    |  paper |   1    |
+-----------------------------------+

what I actually wanted is the following

+-----------------------------------+
|class | subclass |  term  | weight |
+-----------------------------------+
|  a   |     b    |  this  |   1    |
+-----------------------------------+
|  a   |     b    |  this  |   1    |
+-----------------------------------+
|  a   |     b    |  this  |   1    |
+-----------------------------------+
|  a   |     b    |  this  |   1    |
+-----------------------------------+
|  c   |     d    |  paper |   1    |
+-----------------------------------+

I there any other way to get all the results without IN "cutting" only distinct values? The problem is that I cannot change that part: ('this','paper','present','this','and','this','this') because it is not created by a query. It is a string of words I want to search.

Is there any other solution?

Aucun commentaire:

Enregistrer un commentaire