Karthikeya Boyini has Published 2193 Articles

How to copy data from one field to another on every row in MySQL?

karthikeya Boyini

karthikeya Boyini

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

2K+ Views

To copy data from one field to another on every row, use the UPDATE command.Let us first create a table −mysql> create table DemoTable    (    StudentId int,    StudentFirstName varchar(20),    StudentMarks int default 0    ); Query OK, 0 rows affected (0.49 sec)Following is the query to ... Read More

Duration withNanos() method in Java

karthikeya Boyini

karthikeya Boyini

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

116 Views

The immutable copy of a duration with the required nanoseconds is obtained using the method withNanos() in the Duration class in Java. This method requires a single parameter i.e. the number of nanoseconds and it returns the duration with the required nanoseconds that were passed as a parameter.A program that ... Read More

Working with Time in PHP/ MySQL?

karthikeya Boyini

karthikeya Boyini

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

257 Views

To work with time in PHP/ MySQL, you can use strtotime() function. The PHP code is as follows for the same −$timeValue='8:55 PM'; $changeTimeFormat = date('H:i:s', strtotime($timeValue)); echo("The change Format in 24 Hours="); echo($changeTimeFormat);The snapshot of PHP code is as follows −Here is the output.Here is the MySQL query to ... Read More

Create array with MongoDB query?

karthikeya Boyini

karthikeya Boyini

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

2K+ Views

You can use the concept of toArray() to create array. Following is the syntax −db.yourCollectonName.find({}, {yourFieldName:1}).toArray();Let us create a collection with documents −> db.createArrayDemo.insertOne({"UserName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd6461de8cc557214c0e00") } > db.createArrayDemo.insertOne({"UserName":"David"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd6467de8cc557214c0e01") } > db.createArrayDemo.insertOne({"UserName":"Robert"}); {   ... Read More

ROW_NUMBER() equivalent in MySQL for inserting?

karthikeya Boyini

karthikeya Boyini

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

802 Views

There is no equivalent of ROW_NUMBER() in MySQL for inserting but you can achieve this with the help of variable. The syntax is as follows −SELECT (@yourVariableName:=@yourVariableName + 1) AS `anyAliasName`, yourColumnName1, yourColumnName2, ...N FROM yourTableName ,(SELECT @yourVariableName:=0) AS anyAliasName;To understand the above syntax, let us create a table. The ... Read More

Instant range() method in Java

karthikeya Boyini

karthikeya Boyini

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

739 Views

The range of values for a field can be obtained using the range() method in the Instant class in Java. This method requires a single parameter i.e. the ChronoField for which the range of values are required and it returns the range of valid values for the ChronoField.A program that ... Read More

How do I find out the default server character set in MySQL?

karthikeya Boyini

karthikeya Boyini

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

405 Views

You can use system variables character_set_server to know the default server character set in MySQL. Following is the syntax −SHOW VARIABLES LIKE 'character_set_server';Additionally, to u can use collation_server system variable to know the default collation in MySQL. Following is the syntax −SHOW VARIABLES LIKE 'collation_server';Let us execute the above syntaxes ... Read More

Duration minusNanos() method in Java

karthikeya Boyini

karthikeya Boyini

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

69 Views

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

MySQL query to skip the duplicate and select only one from the duplicated values

karthikeya Boyini

karthikeya Boyini

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

1K+ Views

The syntax is as follows to skip the duplicate value and select only one from the duplicated values −select min(yourColumnName1), yourColumnName2 from yourTableName group by yourColumnName2;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table doNotSelectDuplicateValuesDemo    -> ... Read More

How to update record in MongoDB without replacing the existing fields?

karthikeya Boyini

karthikeya Boyini

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

369 Views

You can use $set operator for this Let us first create a collection with documents −> db.updateRecordDemo.insertOne({"StudentName":"Larry"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd6f95de8cc557214c0e0a") } > db.updateRecordDemo.insertOne({"StudentName":"David"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd6f9cde8cc557214c0e0b") } > db.updateRecordDemo.insertOne({"StudentName":"Mike"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd6f9dde8cc557214c0e0c") ... Read More

Advertisements