Samual Sam has Published 2492 Articles

Deleting all rows older than 5 days in MySQL

Samual Sam

Samual Sam

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

1K+ Views

To delete all rows older than 5 days, you can use the following syntax −delete from yourTableName    where datediff(now(), yourTableName.yourDateColumnName) > 5;Note − Let’s say the current date is 2019-03-10.To understand the concept, let us create a table. The query to create a table is as follows −mysql> create ... Read More

Duration minusMinutes() method in Java

Samual Sam

Samual Sam

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

71 Views

An immutable copy of a duration where some minutes are removed from it can be obtained using the minusMinutes() method in the Duration class in Java. This method requires a single parameter i.e. the number of minutes to be subtracted and it returns the duration with the subtracted minutes.A program ... Read More

Add a value to Triplet class in JavaTuples

Samual Sam

Samual Sam

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

129 Views

The addAtX() method is used to add value to the Triplet Tuple. The index can be set here with the X i.e. the place where the value gets added.Let us first see what we need to work with JavaTuples. To work with Triplet class in JavaTuples, you need to import ... Read More

Instant truncatedTo() method in Java

Samual Sam

Samual Sam

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

565 Views

An immutable truncated Instant can be obtained using the truncatedTo() method in the Instant class in Java. This method requires a single parameter i.e. the TemporalUnit till which the Instant is truncated and it returns the immutable truncated Instant.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; ... Read More

MySQL query to retrieve records from the part of a comma-separated list?

Samual Sam

Samual Sam

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

443 Views

To retrieve records from the part of a comma-separated list, you can use built in function FIND_IN_SET().Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(20),    Marks varchar(200)    ); Query OK, 0 rows affected (0.61 ... Read More

Count distinct value in MongoDB?

Samual Sam

Samual Sam

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

307 Views

Use the concept of length to count distinct value. Following is the syntax −db.yourCollectionName.distinct("yourFieldName").length;Let us create a collection with documents −> db.countDistinctDemo.insertOne({"StudentName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd6166de8cc557214c0dfa") } > db.countDistinctDemo.insertOne({"StudentName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd616ade8cc557214c0dfb") } > db.countDistinctDemo.insertOne({"StudentName":"Chris"}); {    "acknowledged" : ... Read More

ByteBuffer asLongBuffer() method in Java

Samual Sam

Samual Sam

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

63 Views

A view of the ByteBuffer can be created as a LongBuffer using the asLongBuffer() method in the class java.nio.ByteBuffer. This method requires no parameters and it returns a long buffer as required. This buffer reflects the changes made to the original buffer and vice versa.A program that demonstrates this is ... Read More

Duration of() method in Java

Samual Sam

Samual Sam

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

143 Views

The required duration using a particular temporal unit can be calculated with the method of() in the Duration class in Java. This method requires two parameters i.e. the time value and the temporal unit for that value. It returns the time duration with the particular value and temporal unit.A program ... Read More

What is the PHP equivalent of MySQL's UNHEX()?

Samual Sam

Samual Sam

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

428 Views

You can use hex2bin() function since it is the PHP equivalent of MySQL's UNHEX().The syntax is as follows −$anyVariableName = hex2bin("yourHexadecimalValue");To understand the above syntax, let us implement the above syntax in PHP. The PHP code is as follows −$myFirstValue = hex2bin("7777772E4D7953514C4578616D706C652E636F6D"); var_dump($myFirstValue); $mySecondValue=hex2bin("416476616E6365644A617661576974684672616D65776F726B"); echo(''); var_dump($mySecondValue);The snapshot of PHP code ... Read More

Setting column values as column names in the MySQL query result?

Samual Sam

Samual Sam

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

3K+ Views

To set column values as column names in the query result, you need to use a CASE statement.The syntax is as follows −select yourIdColumnName, max(case when (yourColumnName1='yourValue1') then yourColumnName2 else NULL end) as 'yourValue1', max(case when (yourColumnName1='yourValue2') then yourColumnName2 else NULL end) as 'yourValue2', max(case when yourColumnName1='yourValue3') then yourColumnName2 else ... Read More

Advertisements