0

I have a table called optima with a few fields and I need to make a query that will return me results where field1 = a and field2 = b.

Table for example

F1 F2
_____
a  z
v  a
a  b
b  a

result must be:

a  b

I was trying to make query like

SELECT * FROM `optima` WHERE `F1` LIKE 'a' AND `F2` LIKE 'b';

but it returns me nothing.

3
  • You seriously need to learn SQL basics. Commented Apr 23, 2012 at 13:46
  • What are the column types (and length) of F1 and F2? Commented Apr 23, 2012 at 14:01
  • Backticks or back quotes are occasionally necessary, but you should avoid them where they are not. The table name does not need backticks; the only reason the column names might need backticks are because they are in upper-case and were enclosed in backticks when the table was created. Commented Apr 23, 2012 at 14:02

1 Answer 1

2

For an exact match, use the = operator, e.g.:

select *
from `optima`
where `F1` = 'a' and `F2` = 'b';
Sign up to request clarification or add additional context in comments.

4 Comments

Do you have backtickitis or something?
I think in this case LIKE is more exact, since it performs comparison character by character and considers trailing spaces. Though, = might be better since trailing spaces will be ignored, which might be the issue.
and what if i need to search something like that: a, b% in table with a, bc? so just use like, not =?
@SergiiRechmp select * from optima where F1 = 'a' and F2 like 'b%';

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.