AmitDiwan has Published 10740 Articles

Find average on the basis of corresponding duplicate VARCHAR values in MySQL

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:56:21

108 Views

Let us first create a table −mysql> create table DemoTable(    Value int,    Value2 varchar(100) ); Query OK, 0 rows affected (0.84 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, '999.999.999.999'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(20, ... Read More

Can we perform MySQL UPDATE and change nothing in a table?

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:55:11

377 Views

Yes, we can do that. Let us first create a table −mysql> create table DemoTable(    Id int ); Query OK, 0 rows affected (1.02 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(201); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable ... Read More

What does select @@identity do in MySQL?

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:53:46

2K+ Views

The @@identity returns the last inserted value in the auto_increment column in the current session. Let us first create a table −mysql> create table DemoTable(    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    UserName varchar(100) ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using ... Read More

MySQL query to fetch the maximum corresponding value from duplicate column values

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:52:33

212 Views

Let us first create a table −mysql> create table DemoTable(    ProductName varchar(100),    ProductPrice int ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Product-1', 56); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Product-2', ... Read More

Will extending the size of a varchar field in MySQL affect the data inside it?

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:50:35

478 Views

If you will extend the size of a varchar field in MySQL then it won’t affect the data inside it.Let us first create a table −mysql> create table DemoTable(    Name varchar(8) ); Query OK, 0 rows affected (1.11 sec)Insert some records in the table using insert command −mysql> insert ... Read More

Sort a list in MySQL and display a fixed result at the end of the column?

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:48:52

117 Views

Let us first create a table −mysql> create table DemoTable(    FirstName varchar(100) ); Query OK, 0 rows affected (0.97 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable values('Adam'); Query OK, 1 row ... Read More

Fetch random rows from a table with MySQL

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:47:30

194 Views

For this, you can use a PREPARE statement. Let us first create a table −mysql> create table DemoTable(    FirstName varchar(100),    CountryName varchar(100) ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Adam', 'US'); Query OK, 1 row ... Read More

How to find repeated rows and display there count in a separate column with MySQL?

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:45:57

151 Views

For this, use the GROUP BY HAVING clause. Let us first create a table −mysql> create table DemoTable(    Name varchar(100),    Age int ); Query OK, 0 rows affected (1.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 23); Query OK, 1 row ... Read More

Select with set order in MySQL

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:44:11

182 Views

For this, you need to use IN() and after that FIELD() method. Let us first create a table −mysql> create table DemoTable(    StudentId varchar(10),    StudentName varchar(20) ) ; Query OK, 0 rows affected (4.11 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('10001', ... Read More

How to search a column for an exact string in MySQL?

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:42:41

2K+ Views

For exact string, you need to use wildcard ‘%’ with LIKE operator −select *from yourTableName where binary yourColumnName LIKE '%yourStringValue%';Let us first create a table −mysql> create table DemoTable(    Name varchar(20) ); Query OK, 0 rows affected (1.93 sec)Insert some records in the table using insert command −mysql> insert ... Read More

Advertisements