Kumar Varma has Published 107 Articles

MySQL query to update every alternative row string having same values?

Kumar Varma

Kumar Varma

Updated on 30-Jul-2019 22:30:26

248 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Subject varchar(100)    -> ); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Subject) values('C'); Query ... Read More

What is the PHP stripos() equivalent in MySQL?

Kumar Varma

Kumar Varma

Updated on 30-Jul-2019 22:30:26

161 Views

The stripos() equivalent in MySQL is INSTR(), which returns the position of the first occurrence of a string in another string. Following is the syntax −select instr(yourColumnName, yourWord) As anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable    -> (    -> Title text    -> ... Read More

How to lowercase the entire string keeping the first letter in uppercase with MySQL?

Kumar Varma

Kumar Varma

Updated on 30-Jul-2019 22:30:26

148 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(100)    -> ); Query OK, 0 rows affected (1.32 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('JOhn'); Query OK, 1 row affected (0.17 sec) mysql> insert ... Read More

SELECT last entry without using LIMIT in MySQL?

Kumar Varma

Kumar Varma

Updated on 30-Jul-2019 22:30:26

1K+ Views

For this, you can use subquery. Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(100)    -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command ... Read More

How to extract substring from a sting starting at a particular position in MySQL?

Kumar Varma

Kumar Varma

Updated on 30-Jul-2019 22:30:26

251 Views

For this, you can use the mid() function. Following is the syntax −select mid(yourColumnName, yourPositionToStart, yourEndValue) as anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable    -> (    -> Title text    -> ); Query OK, 0 rows affected (0.64 sec)Insert some records in the ... Read More

MySQL query with OR & AND conditions

Kumar Varma

Kumar Varma

Updated on 30-Jul-2019 22:30:26

177 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20),    -> Age int    -> ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert ... Read More

How to get the previous day with MySQL CURDATE()?

Kumar Varma

Kumar Varma

Updated on 30-Jul-2019 22:30:26

319 Views

Let us first get the current date using CURDATE(). The current date is as follows −mysql> select CURDATE(); +------------+ | CURDATE() | +------------+ | 2019-06-09 | +------------+ 1 row in set (0.00 sec)Let us first create a table −mysql> create table DemoTable    -> (    -> Id int ... Read More

MySQL query to avoid displaying duplicates values?

Kumar Varma

Kumar Varma

Updated on 30-Jul-2019 22:30:26

505 Views

For this, you can use GROUP BY and use COUNT to get only non-duplicate values. Following is the syntax −select yourColumnName from yourTableName group by yourColumnName having count(*)=1;Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,   ... Read More

Set AUTO_INCREMENT in a table while creating it in MySQL?

Kumar Varma

Kumar Varma

Updated on 30-Jul-2019 22:30:26

189 Views

Let us first create a table. We have used AUTO_INCREMENT while creating the table to set auto increment for StudentId −mysql> create table DemoTable    -> (    -> StudentId int NOT NULL AUTO_INCREMENT,    -> StudentFirstName varchar(100),    -> StudentLastName varchar(100),    -> StudentAge int,    -> StudentCountryName varchar(100), ... Read More

MySQL query to count where more than three columns values are true?

Kumar Varma

Kumar Varma

Updated on 30-Jul-2019 22:30:26

171 Views

To count where more than three column values are true, you can use WHERE clause. Let us first create a table −mysql> create table DemoTable    -> (    -> isMarried boolean,    -> isActive boolean,    -> isMember boolean,    -> isOn boolean    -> ); Query OK, 0 ... Read More

Advertisements