
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Comparing two strings in MySQL?
To compare two strings, which are numbers, let us first create a table. Following is the query −
mysql> create table compareTwoStringsDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Value varchar(100) -> ); Query OK, 0 rows affected (0.52 sec)
Following is the query to insert some records in the table using insert command −
mysql> insert into compareTwoStringsDemo(Value) values('1235667'); Query OK, 1 row affected (0.66 sec) mysql> insert into compareTwoStringsDemo(Value) values('999999'); Query OK, 1 row affected (0.11 sec) mysql> insert into compareTwoStringsDemo(Value) values('999888'); Query OK, 1 row affected (0.17 sec) mysql> insert into compareTwoStringsDemo(Value) values('567433'); mysql> insert into compareTwoStringsDemo(Value) values('567433'); Query OK, 1 row affected (0.23 sec) mysql> insert into compareTwoStringsDemo(Value) values('2345123'); Query OK, 1 row affected (0.13 sec)
Following is the query to display all records from the table using select statement −
mysql> select *from compareTwoStringsDemo;
This will produce the following output −
+----+---------+ | Id | Value | +----+---------+ | 1 | 1235667 | | 2 | 999999 | | 3 | 999888 | | 4 | 567433 | | 5 | 2345123 | +----+---------+ 5 rows in set (0.00 sec)
Following is the query to compare two strings which are numbers −
mysql> select *from compareTwoStringsDemo -> where cast(Value as signed) = 999999;
This will produce the following output. The record with the matching string gets displayed −
+----+--------+ | Id | Value | +----+--------+ | 2 | 999999 | +----+--------+ 1 row in set (0.00 sec)
- Related Articles
- Comparing two strings in C++
- Comparing two Strings lexicographically in Java \n
- Comparing Strings and Portions of Strings in Java
- Comparing ascii scores of strings - JavaScript
- Comparing Strings with (possible) null values in java?
- Concatenating two strings in MySQL with space?
- Comparing two dates in PHP
- Comparing two columns in a single MySQL query to get one row?
- How to add two or more strings in MySQL?
- How to check similarity between two strings in MySQL?
- How to compare two strings which are numbers in MySQL?
- Comparing corresponding values of two arrays in JavaScript
- Comparing integers by taking two numbers in JavaScript
- Why does comparing types in MySQL won’t raise an error?
- Compare date strings in MySQL

Advertisements