0
SELECT * FROM pg_requisition WHERE brands = any(1, 2, 32)

This is my Query , where I have a record in my database as 31,2 but the above query doesnt show me the result .

Whereas if I check with the query as

SELECT * FROM pg_requisition WHERE brands = any(1, 31, 32) 

it shows the result.

Can Any one help as how to match the data from the start to the end and if found must return the output

step
  • 2,254
  • 2
  • 23
  • 45

1 Answers1

1

Try the In clause.

SELECT * FROM pg_requisition WHERE brands IN (1, 2, 32);

Edit

Whereas if I check with the query as SELECT * FROM pg_requisition WHERE brands = any(1, 31, 32) it shows the result.

I assume you're talking about your sql-developer-tools.

If the tools display all the results it means that your query is correct, but it probably means that the way you're receiving the data is incorrect in your code.

You're probably just fetching the first result, or non at all, even though you get the data back, you need to learn how to iterate through the results and parse the selected rows.

Jonast92
  • 4,964
  • 1
  • 18
  • 32
  • I have already Tried with in , but in only checks if it matches the first number – Manish Yadav Jun 26 '14 at 10:07
  • Have you tried using those commands in your sql console or only in PHP code? – Jonast92 Jun 26 '14 at 10:09
  • Ya in my phpmyadmin SQL Console Window I tried , where I have seen its working fine when my string starts with 31,2 but it fails in case where I have 2,31 – Manish Yadav Jun 26 '14 at 10:14
  • ANY returns a bool value. ANY returns as soon as it finds the first matching row so the order of the rows matter, you should stick with IN. anyway showing us the php code would help, along with the results from your phpmyadmin. I don't like to guess about what's happening, I'd like to see it. – Jonast92 Jun 26 '14 at 10:19
  • First Query -> SELECT COUNT( * ) FROM pg_requisition WHERE brands IN ( 1, 2, 32 ) Second Query ->SELECT COUNT( * ) FROM pg_requisition WHERE brands IN ( 1, 31, 32 ) one common Field with Data 31,2 The ablove query will return 0 whereas second will return 1 – Manish Yadav Jun 26 '14 at 10:28