Use MySQL INSTR Function with WHERE Clause

Chandu yadav
Updated on 04-Feb-2020 06:10:29

1K+ Views

When we use INSTR() function with MySQL WHERE clause, we need to provide column name of the table as the first argument and the substring as second argument along with a comparison operator. Following is an example using ‘Student’ table to demonstrate it −ExampleSuppose we have the following values in ‘Student’ table −mysql> Select * from Student; +------+---------+---------+-----------+ | Id   | Name    | Address | Subject   | +------+---------+---------+-----------+ | 1    | Gaurav  | Delhi   | Computers | | 2    | Aarav   | Mumbai  | History   | | 15   | Harshit | ... Read More

Import Text File Data into MySQL Table

varun
Updated on 04-Feb-2020 06:08:24

317 Views

Actually, we can write the data on the same line in the text file by using a separator. In this case, while importing this text file into MySQL table then we must have to use ‘LINES TERMINATED BY’ option. It can be understood with the help of the following example −Suppose we are using ‘|’ as the LINE TERMINATOR symbol in a text file as follows −id, Name, Country, Salary|105, Chum*, Marsh, USA, 11000|106, Danny*, Harrison, AUS, 12000Now while importing this text file into MySQL table then we need to mention ‘LINE TERMINATED BY’ option also in the query as ... Read More

Predicting Customer Churn in Python

Pradeep Elance
Updated on 04-Feb-2020 06:07:21

645 Views

Every business depends on customer's loyalty. The repeat business from customer is one of the cornerstone for business profitability. So it is important to know the reason of customers leaving a business. Customers going away is known as customer churn. By looking at the past trends we can judge what factors influence customer churn and how to predict if a particular customer will go away from the business. In this article we will use ML algorithm to study the past trends in customer churn and then judge which customers are likely to churn.Data PreparationAs an example will consider the Telecom ... Read More

Import Specific Columns from Text File into MySQL Table

Sravani S
Updated on 04-Feb-2020 06:04:45

1K+ Views

Suppose if we have the values for some specific columns in the text file and MySQL table, in which we want to import the data, is having an extra column(s) then by mentioning the names of the columns in the query we can upload the values of those specific columns only. It can be understood with the help of the following example −ExampleSuppose we are having the values of columns ‘id’, ‘Name’ and ‘Salary’ only in the text file as follows −105, Chum, 11000 106, Danny, 12000Now while importing this text file into MySQL table then we need to mention ... Read More

Difference Between MySQL INSTR and FIND IN SET Functions

Lakshmi Srinivas
Updated on 04-Feb-2020 06:03:15

556 Views

As we know, both the functions are used to search a string from the arguments provided in them but there are some significant differences between them as followsFIND_IN_SET() function uses the string list that is itself a string containing the substring separated by commas. Whereas, INSTR() function contains a string from which it will find the position of the first occurrence of the substring if present. In case of integers, FIND_IN_SET() is much more suitable than INSTR() function. It can be understood by the following exampleExamplemysql> Select IF(INSTR('10, 11, 12, 13', 2) > 0, 1, 0) As Result; +--------+ | Result ... Read More

MySQL Functions to Change Character Case of a String

Kumar Varma
Updated on 04-Feb-2020 06:02:25

216 Views

We can use LCASE() and LOWER() functions for changing the character case of a string to lower case and UCASE() and UPPER() functions for changing the character case of a string to upper case.Examplemysql> Select LCASE('NEW DELHI'); +--------------------+ | LCASE('NEW DELHI') | +--------------------+ | new delhi          | +--------------------+ 1 row in set (0.00 sec) mysql> Select LOWER('NEW DELHI'); +--------------------+ | LOWER('NEW DELHI') | +--------------------+ | new delhi          | +--------------------+ 1 row in set (0.00 sec) mysql> Select UCASE('new delhi'); +--------------------+ | UCASE('new delhi') | +--------------------+ ... Read More

Find String of Specified Pattern in Another String Using MySQL

Ankith Reddy
Updated on 04-Feb-2020 06:00:45

137 Views

We can find a string of specified pattern within another string by using LIKE operator along with WILDCARDS.SyntaxLIKE specific_patternSpecific_pattern is the pattern of string we want to find out within another string.ExampleSuppose we have a table named ‘student’ having names of the students and we want to get the details of all those students which are having the pattern of string ‘av’ within their names. It can be done with the help of following MySQL query −mysql> Select * from Student Where Name LIKE '%av%'; +------+--------+---------+-----------+ | Id   | Name   | Address | Subject   | +------+--------+---------+-----------+ ... Read More

Import Data from TXT File into MySQL Table

radhakrishna
Updated on 04-Feb-2020 05:58:37

4K+ Views

It can be done with the help of LOAD DATA INFILE statement. To illustrate the concept we are having the following data, separated by tab, in ‘A.txt’ whose path is d:/A.txt −100 John  USA 10000 101 Paul  UK  12000 102 Henry NZ  11000 103 Rick  USA 17000 104 Corey USA 15000We want to load the data of A.txt into the following table named employee_tbl −mysql> Create table employee_tbl(Id Int, Name varchar(20), Country Varchar(20), Salary Int); Query OK, 0 rows affected (0.91 sec)Now, the transfer of data from a file to a database table can be done with the help ... Read More

Understanding CONV Function Value Constraints

Paul Richard
Updated on 04-Feb-2020 05:57:20

172 Views

MySQL returns 0 as output if the number given in CONV() function is not as per accordance with its base. Suppose, if we want to convert decimal number 9 into the number in binary number system then in this case the value of from_base must be 10 but if we provide 8 as the value of from_base then MySQL returns 0 as output.Examplemysql> Select CONV(9,8,2); +-------------+ | CONV(9,8,2) | +-------------+ | 0           | +-------------+ 1 row in set (0.00 sec)As we know that the values of octal number system must be between 0 to 7, hence the number system for number 9 must be decimal i.e. 10.

Limits of Base in MySQL CONV Function

Ankith Reddy
Updated on 04-Feb-2020 05:56:40

141 Views

The base must be greater than 2 and less than 36 i.e. the lower limit of a base is 2 and the upper limit is 36. It is applied to both from_base and to_base values. If in case we provide out of limit values of the base then MySQL returns NULL as the output. Following example will demonstrate it −Examplemysql> Select CONV(10,10,38); +----------------+ | CONV(10,10,38) | +----------------+ | NULL           | +----------------+ 1 row in set (0.00 sec) mysql> Select CONV(10,72,2); +---------------+ | CONV(10,72,2) | +---------------+ | NULL          | +---------------+ 1 row in set (0.00 sec) mysql> Select CONV(10,10,1); +---------------+ | CONV(10,10,1) | +---------------+ | NULL          | +---------------+ 1 row in set (0.00 sec)

Advertisements