mlms133
mlms133

Reputation: 53

Mysql comparing two string with capital and not

firstname   lastname
John        doe
Doe         Mill

how to select * from table where firstname=lastname

what i want is query displaying 0 result because Doe in firstname have D capital letter

Upvotes: 1

Views: 39

Answers (3)

Bohemian
Bohemian

Reputation: 425458

Use LIKE, which is case insensitive:

select * from table
where firstname like lastname

See live demo on SQLFiddle.

Upvotes: 0

rhavendc
rhavendc

Reputation: 1011

You can use BINARY for selecting as is data:

SELECT * FROM table WHERE BINARY firstname = lastname

The BINARY operator casts the string following it to a binary string. This is an easy way to force a comparison to be done byte by byte rather than character by character. BINARY also causes trailing spaces to be significant.

Examples:

  • A == A
  • AaA == AaA
  • A != a
  • AaA != AAA

See: The BINARY Operator

Upvotes: 1

Priyanshu
Priyanshu

Reputation: 881

select firstname,lastname from table where upper(firstname) = upper(lastname);

Upvotes: 1

Related Questions