0

I've got a mysql table with the following data:

ID | Name
1 | xy 
4 | dasd
9 | 422p
10 | dasös

and I've got the following query which should display only the values "1 and 4", but it displays 1,4,10.

rlike '1|^4'    

any idea?

Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
Stefan
  • 13
  • 4
  • 2
    This may be only due to your choice of example data, but why would you use `RLIKE` for this rather than `IN(1,4)`? If you in fact have more complicated row data, it would help if you posted a more representative example. – Michael Berkowski Sep 27 '14 at 12:54
  • I'll need your help with the following code. If there is no tickets with the prio_id 5 it should be displayed "ok" and when there one or more tickets with an higher priority it should be a image displayed Prio-Tickets = 0 ) { echo 'OK'; } else { echo '' }} ?> – Stefan Sep 27 '14 at 13:07
  • 1
    This being unrelated to your existing question here, you need to ask it as a new question rather than expand the old one to a very different scope in the comment thread. – Michael Berkowski Sep 27 '14 at 13:10
  • Please tell exactly what you want to achieve, as if its 4, 1, 40 then what should be the output ? – Abhishek Gupta Sep 27 '14 at 13:13
  • You may use MySQL REGEX as well: SELECT * FROM table WHERE col REGEXP '^[1,4]$' – Benvorth Sep 27 '14 at 20:05

1 Answers1

0

If you insistence for use RLIKE, You can use this query:

SELECT * FROM `test` WHERE `id` RLIKE '^1$|^4$';

See online: http://sqlfiddle.com/#!9/c0ede/1/0

But better then and more efficient and more principled and faster then is use IN, be like this:

SELECT * FROM `test` WHERE `id` IN (1, 4);

See online: http://sqlfiddle.com/#!9/c0ede/2/0

Thanks

Nabi K.A.Z.
  • 9,887
  • 6
  • 59
  • 81