1

I'm looking for an easy way to find if two given numbers are in the same row, without using WHERE and OR in MySQL.

The table schema is like this

Field1 | Field2 | Field3 | Field4 | Field5 | Field6
  0        0        3        0        0        4
  1        5        0        0        0        0
  0        0        2        0        6        0

For example, I would like to know if 3 and 6 are in the same row, and return TRUE or FALSE.

I am looking for something like this pesudo code: SELECT ID FROM Table WHERE :mynumber AND :myothernumber is :inthesamerow?

Thank you!

6
  • 1
    Welcome to Stack Overflow! Open-ended "How to" questions are difficult to answer, and tend to generate follow-up discussions. To improve your chances of getting a helpful answer, edit your question to provide greater focus on the specific problem you're facing. See How to Ask. Commented Sep 4, 2015 at 14:51
  • "Good afternoon" - It's still "morning" here ;-) Commented Sep 4, 2015 at 14:55
  • There's no other way for me to explane, I've really no ideas to suggest... Commented Sep 4, 2015 at 14:55
  • Your data example suggests that your columns are most likely VARCHAR and not an INT type, correct? Unless it's unsigned. dev.mysql.com/doc/refman/5.0/en/integer-types.html Commented Sep 4, 2015 at 14:57
  • The next answare has resolved this problem :) Thank you guys, and @Fred -ii- not where I live :) Commented Sep 4, 2015 at 15:04

2 Answers 2

1

You can use the mysql IN commando

SELECT * FROM table WHERE 'valueA' IN(field1, field2, field3, field4, ..) AND 'valueB' IN(field1, field2, field3, field4, ..);

Sign up to request clarification or add additional context in comments.

1 Comment

This is helped me alot, now it's working, thank you :)
1

http://sqlfiddle.com/#!9/93bb8e/2

SELECT *
FROM table
WHERE (Field1=3 OR Field2=3 OR Field3=3 OR Field4=3 OR Field5=3 OR Field6=3  )
   AND (Field1=6 OR Field2=6 OR Field3=6 OR Field4=6 OR Field5=6 OR Field6=6  )

7 Comments

Thank you for the answare, I cannot like this, because the numbers change usually, and I've more than two or 3 rows, this is an ex...
this query will return as many rows as many match to the clause you asked for
@JasmineVismitananda, why do you think this suggestion will not work? did you tried at least?
Alex, you could as well use where 3 in (field1,field2, ...)
Yes, but I've to filter in PDO 12 numbers :) with IN as @sanderbee and Rahul suggested working better, thank you alot for your fast help!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.