Chandu yadav has Published 1090 Articles

Remove all the elements from an ArrayList that are in another Collection in Java

Chandu yadav

Chandu yadav

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

167 Views

The method java.util.ArrayList.removeAll() removes all the the elements from the ArrayList that are available in another collection. This method has a single parameter i.e. the Collection whose elements are to be removed from the ArrayList.A program that demonstrates this is given as followsExample Live Demoimport java.util.ArrayList; import java.util.List; public class Demo ... Read More

Using single quotes around database and table name isn’t working in MySQL?

Chandu yadav

Chandu yadav

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

667 Views

You need to use backticks around table name as well as database name. The syntax is as follows:UPDATE `yourDatabaseName`.`yourTableName` SET yourColumnName1=yourColumnName1+1 WHERE yourColumnName2=’yourValue’;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> use test; Database changed mysql> create table Add1Demo   ... Read More

How to Reset MySQL AutoIncrement using a MAX value from another table?

Chandu yadav

Chandu yadav

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

1K+ Views

You can use prepare statement to Reset MySQL AutoIncrement using a MAX value from another table.The following is the syntax −set @anyVariableName1=(select MAX(yourColumnName) from yourTableName1); SET @anyVariableName2 = CONCAT('ALTER TABLE yourTableName2 AUTO_INCREMENT=', @anyVariableName1); PREPARE yourStatementName FROM @anyVariableName2; execute yourStatementName;The above syntax will reset MySQL auto_increment using a maximum value from ... Read More

Can MySQL automatically store timestamp in a row?

Chandu yadav

Chandu yadav

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

3K+ Views

Yes, you can achieve this in the following two ways.First Approach At the time of creation of a table.Second Approach At the time of writing query.The syntax is as follows.CREATE TABLE yourTableName ( yourDateTimeColumnName datetime default current_timestamp );You can use alter command.The syntax is as follows.ALTER TABLE yourTableName ADD yourColumnName ... Read More

How to delete last record (on condition) from a table in MySQL?

Chandu yadav

Chandu yadav

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

9K+ Views

To delete last record (on condition) from a table, you need to use ORDER BY DESC with LIMIT 1. The syntax is as follows:DELETE FROM yourTableName WHERE yourColumnName1=yourValue ORDER BY yourColumnName2 DESC LIMIT 1;The above syntax will delete last record (on condition) from a table. It sorts the column in descending ... Read More

MySQL increment a database field by 1?

Chandu yadav

Chandu yadav

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

4K+ Views

You can increment a database using update command. The syntax is as follows −UPDATE yourTableName set yourColumnName=yourColumnName+1 where condition;To understand the above syntax, let us first create a table. The query to create a table is as follows −mysql> create table IncrementBy1    -> (    -> Id int,   ... Read More

Change MySQL default character set to UTF-8 in my.cnf?

Chandu yadav

Chandu yadav

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

1K+ Views

To change MySQL default character set to UTF-8 in my.cnf, firstly reach the location of my.cnf file.The following is the screenshot of “my.cnf” file. Firstly, open the C: directory and the “Program Data” folder −Now, click on “MySQL” folder −Now, click the MySQL Server 8.0 folder and open it −After ... Read More

Get Last Entry in a MySQL table?

Chandu yadav

Chandu yadav

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

2K+ Views

You can get the last entry in a MySQL table using ORDER BY. The first approach is as follows:Case 1: Using DESC LIMITSELECT * FROM yourTableName ORDER BY yourColumnName DESC LIMIT 1;The second approach is as follows:Case 2: Using MAX()SET @anyVariableName = (SELECT MAX(yourColumnName) FROM yourTableName); SELECT *FROM yourtableName WHERE ... Read More

BOOLEAN or TINYINT to store values in MySQL?

Chandu yadav

Chandu yadav

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

631 Views

The MySQL BOOLEAN and BOOL both are equivalent to TINYINT(1). Whenever you create a column using BOOLEAN and BOOL data type, MySQL implicitly convert the BOOLEAN and BOOL to TINYINT(1). The BOOLEAN and BOOL are equivalents of TINYINT(1), since they are synonyms.Create a table using BOOLEAN data type. The query ... Read More

Grab where current date and the day before with MySQL?

Chandu yadav

Chandu yadav

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

2K+ Views

You can grab the current date with CURDATE() and the day before with MySQL using DATE_SUB() with INTERVAL 1 DAY. The syntax is as follows:SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY);The syntax is as follows to get curdate and the day before with date_sub().SELECT *FROM yourTableName WHERE yourColumnName = CURDATE() OR yourColumnName ... Read More

Advertisements