Chandu yadav has Published 1163 Articles

How to find the previous and next record using a single query in MySQL?

Chandu yadav

Chandu yadav

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

6K+ Views

You can use UNION to get the previous and next record in MySQL.The syntax is as follows(select *from yourTableName WHERE yourIdColumnName > yourValue ORDER BY yourIdColumnName ASC LIMIT 1) UNION (select *from yourTableName WHERE yourIdColumnName < yourValue ORDER BY yourIdColumnName DESC LIMIT 1);To understand the concept, let us create a ... Read More

Can namespaces be nested in C++?

Chandu yadav

Chandu yadav

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

154 Views

Yes the namespace can be nested in C++. We can define one namespace inside another name space as follows −Syntaxnamespace namespace_name1 {    // code declarations    namespace namespace_name2 {       // code declarations    } }You can access members of nested namespace by using resolution operators as ... Read More

LongStream findFirst() method in Java

Chandu yadav

Chandu yadav

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

88 Views

The findFirst() method of the LongStream class in Java returns an OptionalLong describing the first element of this stream, or an empty OptionalLong if the stream is empty.The syntax is as follows.OptionalLong findFirst()Here, OptionalLong is a container object which may or may not contain a long value. For OptionalLong, import ... Read More

ArrayBlockingQueue add() method in Java

Chandu yadav

Chandu yadav

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

64 Views

To add elements to the ArrayBlockingQueue class, use the add() method.The syntax is as followsboolean add(E ele)Here, ele is the element to be added to the queue. To work with ArrayBlockingQueue class, you need to import the following packageimport java.util.concurrent.ArrayBlockingQueue;The following is an example to add elements in Java ArrayBlockingQueue classExample Live ... Read More

Only insert if a value is unique in MongoDB else update

Chandu yadav

Chandu yadav

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

633 Views

You can use upsert i.e. whenever you insert a value and it already exist then update would be performed. If the value does not already exist then it would get inserted.Let us first create a collection with documents> db.onlyInsertIfValueIsUniqueDemo.insertOne({"StudentName":"Larry", "StudentAge":22}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a633815e86fd1496b38a4") } ... Read More

Does MySQL have an expanded output flag similar PostgreSQL?

Chandu yadav

Chandu yadav

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

83 Views

Yes, you can get expanded out in MySQL using the /G, instead of semicolon(;). The syntax is as followsSELECT *FROM yourTableName\GLet us first create a table as an examplemysql> create table expandedOutputDemo    - > (    - > EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    - > EmployeeName ... Read More

Copy-and-Swap Idiom in C++

Chandu yadav

Chandu yadav

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

200 Views

The assignment consists of 2 steps, tearing an object's old state and building a new state for it. The destructor is used for the first step and a copy constructor does the second step.Implementing both of these is straightforward. But when overloading the assignment operator, it can become quite difficult ... Read More

LongStream mapToInt() method in Java

Chandu yadav

Chandu yadav

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

753 Views

The mapToInt() method returns an IntStream consisting of the results of applying the given function to the elements of this stream.The syntax is as followsmapToInt(LongToIntFunction mapper)Here, the parameter mapper is the stateless function applied to each element.Declare LongStream and add some elementsLongStream longStream = LongStream.of(1000L, 13000L, 18000L);Now, use the IntStream ... Read More

Perform conditional upserts or updates in MongoDB

Chandu yadav

Chandu yadav

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

98 Views

For conditional upserts or updates, you can use $max operator. Let us first create a collection with documents>db.conditionalUpdatesDemo.insertOne({"_id":100, "StudentFirstScore":89, "StudentSecondScore":78, "BiggestScore":89}); { "acknowledged" : true, "insertedId" : 100 } >db.conditionalUpdatesDemo.insertOne({"_id":101, "StudentFirstScore":305, "StudentSecondScore":560, "BiggestScore":1050}); { "acknowledged" : true, "insertedId" : 101 } >db.conditionalUpdatesDemo.insertOne({"_id":103, "StudentFirstScore":560, "StudentSecondScore":789, "BiggestScore":880}); { "acknowledged" : true, "insertedId" ... Read More

fabs() in C++

Chandu yadav

Chandu yadav

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

488 Views

The C or C++ library function double fabs(double x) returns the absolute value of x. x − This is the floating point value. This function returns the absolute value of x. Following is the declaration for fabs() function.double fabs(double x)The following example shows the usage of fabs() function.Example Live Demo#include ... Read More

Advertisements