AmitDiwan has Published 10744 Articles

Combine SELECT & SHOW command results in MySQL?

AmitDiwan

AmitDiwan

Updated on 19-Nov-2020 11:28:09

353 Views

To combine SELECT and SHOW command results into one, use the below query −select @anyVariableName1 as anyAliasName1, @anyVariableName1 as anyAliasName2, ......N;To combine the SELECT and SHOW, first create and initialize the first variable. Following is the query −mysql> set @first_name='John'; Query OK, 0 rows affected (0.00 sec)To combine the SELECT ... Read More

Regex to find string and next character in a comma separated list - MySQL?

AmitDiwan

AmitDiwan

Updated on 19-Nov-2020 11:25:50

441 Views

To search in a comma separated list, use MySQL find_in_set(). The usage of Regex for this purpose isn’t required here. The syntax is as follows −select *from yourTableName where find_in_set(anyValue, yourColumnName);Let us create a table −mysql> create table demo17 −> ( −> id int not null auto_increment primary key, −> ... Read More

How can I extract minute from time in BigQuery in MySQL?

AmitDiwan

AmitDiwan

Updated on 19-Nov-2020 11:22:56

233 Views

Extract using extract() method along with cast(). Following is the syntax −select extract(minute from cast(yourColumnName as time)) as anyAliasName from yourTableName;Let us create a table −mysql> create table demo15 −> ( −> value time −> ); Query OK, 0 rows affected (2.11 sec)Insert some records into the table with the ... Read More

Need help in deleting duplicate columns from a table in MySQL?

AmitDiwan

AmitDiwan

Updated on 19-Nov-2020 11:21:07

421 Views

To delete duplicate columns, use DELETE with INNER JOIN. Following is the syntax −delete tbl1 from yourTableName anyAliasName1 inner join yourTableName anyAliasName2 where yourCondition1 and yourCondition2Let us create a table −mysql> create table demo14 −> ( −> id int not null auto_increment primary key, −> name varchar(30) −> ); Query ... Read More

Update a table in MySQL and display only the initials name in a new column

AmitDiwan

AmitDiwan

Updated on 19-Nov-2020 11:18:11

526 Views

To get the initial, use the concept of left() along with substring_index().Let us create a table −mysql> create table demo13 −> ( −> full_name varchar(100), −> short_name varchar(20) −> ); Query OK, 0 rows affected (1.18 sec)Insert some records into the table with the help of insert command −mysql> insert ... Read More

Add some months to current date using Java with MySQL?

AmitDiwan

AmitDiwan

Updated on 19-Nov-2020 11:15:54

294 Views

Following is the syntax to add months using INTERVAL with Java − MySQL.String query; query = "insert into yourTableName values(curdate()+interval howManyNumberOfMonths month)";Following is the current date −mysql> select curdate(); +------------+ | curdate() | +------------+ | 2020-10-25 | +------------+ 1 row in set (0.00 sec)Let us create a table −mysql> ... Read More

How to get substring results from a table with file location recordsi in MySQL?

AmitDiwan

AmitDiwan

Updated on 19-Nov-2020 11:11:23

183 Views

To fetch sub strings, use the substr() method in MySQL as in the below syntax −select substr(yourColumnName, startIndex, endIndex) from yourTableName limit anyValue; select substr(yourColumnName, startIndex+endIndex) from yourTableName limit anyValue;Let us create a table −mysql> create table demo11 −> ( −> id int NOT NULL AUTO_INCREMENT PRIMARY KEY, −> ... Read More

Is there a way to make a list from a MySQL table in Java?

AmitDiwan

AmitDiwan

Updated on 19-Nov-2020 11:07:20

2K+ Views

Yes, for this, use the concept of ArrayList in Java. The syntax is as follows −ArrayList anyVariableName= new ArrayList();Let us create a table −mysql> create table demo10 −> ( −> id int not null auto_increment primary key, −> name varchar(20) −> ); Query OK, 0 rows affected (2.19 sec)Insert some ... Read More

How to merge MySQL results?

AmitDiwan

AmitDiwan

Updated on 19-Nov-2020 11:01:32

369 Views

To merge, use simple join. Following is the syntax −select aliasName1.yourColumnName1, aliasName1.yourColumnName2, . . .N aliasName2.yourColumnName1 from yourTableName1 aliasName1 . . . N join yourTableName2 aliasName2 on yourCondition;Let us create a table −mysql> create table demo8 −> ( −> id int, −> name varchar(20) −> ); Query OK, 0 rows ... Read More

Group result in MySQL and show on list?

AmitDiwan

AmitDiwan

Updated on 19-Nov-2020 10:58:57

138 Views

For this, use GROUP BY along with ORDER BY −select yourColumnName, count(*) as anyAliasName from yourTableName group by yourColumnName order by yourColumnName;Let us create a table −mysql> create table demo7 −> ( −> id int NOT NULL AUTO_INCREMENT, −> first_name varchar(50) −> , −> primary key(id) −> ); Query OK, ... Read More

Advertisements