
- 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
MySQL automatic string to integer casting in WHERE clause to fetch a specific id
If the string begins with integer then it converts the string to integer, otherwise it won’t. Let us first create a −
mysql> create table DemoTable1390 -> ( -> StudentId varchar(20) -> ); Query OK, 0 rows affected (0.93 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1390 values('563_John'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1390 values('1001_Carol_Taylor'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1390 values('David_Miller_789'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable1390 values('456_AdamSmith'); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select −
mysql> select * from DemoTable1390;
This will produce the following output −
+-------------------+ | StudentId | +-------------------+ | 563_John | | 1001_Carol_Taylor | | David_Miller_789 | | 456_AdamSmith | +-------------------+ 4 rows in set (0.00 sec)
Following is the query for automatic string to integer casting in where clause to fetch a specific −
mysql> select * from DemoTable1390 where StudentId=456;
This will produce the following output −
+---------------+ | StudentId | +---------------+ | 456_AdamSmith | +---------------+ 1 row in set, 4 warnings (0.02 sec)
- Related Articles
- Can we fetch multiple values with MySQL WHERE Clause?
- MySQL to Implementing OR operator in a WHERE clause?
- MySQL REGEXP to fetch string + number records beginning with specific numbers?
- Delete a specific record from a MySQL table by using AND in WHERE clause
- How to add a where clause in a MySQL Insert statement?
- How can I achieve similar result like using a loop in MySQL WHERE clause to display only alternate ID records?
- Passing an array to a query using WHERE clause in MySQL?
- How to use MySQL VIEW with WHERE clause?
- How to fetch an Integer variable as String in GoLang?
- MySQL query to select records beginning from a specific id
- Fetch a specific column value (name) in MySQL
- Fetch a specific record from a column with string values (string, numbers and special characters) in MySQL
- How to use MySQL Date functions with WHERE clause?
- How to use MySQL LIKE clause to fetch multiple values beginning with “Joh”
- What is the alternative of BETWEEN clause to fetch values between a range in MySQL?

Advertisements