Order By 0 First and Display Records in Descending Order in MySQL

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

400 Views

In order to order by 0 first and then largest, you can use the below syntax −select *from yourTableName order by yourColumnName=0 DESC, yourColumnName DESC;Let us first create a table −mysql> create table DemoTable (    Value int ); Query OK, 0 rows affected (0.65 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(90); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.12 ... Read More

Implement MySQL INSERT with MAX + 1

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

2K+ Views

You need to use COALESCE() function for this. The syntax is as follows:INSERT INTO yourTableName(yourColumnName1, yourColumnName2) SELECT 1 + COALESCE((SELECT MAX(yourColumnName1) FROM yourTableName WHERE yourColumnName2=’yourValue’), 0), ’yourValue’;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table InsertMaxPlus1Demo    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (1.27 sec)Now you can insert some records in the table using insert command. The query is as follows:mysql> insert into InsertMaxPlus1Demo(Id, Name) values(1, 'John'); Query OK, 1 row affected (0.12 sec) mysql> insert ... Read More

DoubleBuffer equals Method in Java

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

159 Views

The equality of two buffers can be checked using the method equals() in the class java.nio.DoubleBuffer. Two buffers are equal if they have the same type of elements, the same number of elements and the same sequence of elements. The method equals() returns true if the buffers are equal and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          DoubleBuffer buffer1 = DoubleBuffer.allocate(n);         ... Read More

ATM Adaptation Layer (AAL)

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

10K+ Views

In Asynchronous Transfer Mode (ATM) networks, the ATM Adaptation Layer (AAL) provides facilities for non-ATM based networks to connect to ATM network and use its services.AAL is basically a software layer that accepts user data, which may be digitized voice, video or computer data, and makes them suitable for transmission over an ATM network. The transmissions can be of fixed or variable data rate. AAL accepts higher layer packets and segments them into fixed sized ATM cells before transmission via ATM. It also reassembles the received segments to the higher layer packets.The following diagram illustrates the function of AAL −This ... Read More

Use SynchronizedSet in Android

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

189 Views

This example demonstrate about How to use synchronizedSet in Android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.                                 In the above code, we have taken name and record number as Edit text, when user click on save button it will store the data into arraylist. Click on refresh button to get the changes of listview.Step 3 ... Read More

Select Distinct Dates from Datetime Column in MySQL

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

5K+ Views

You need to use DISTINCT keyword to select distinct dates from datetime column in a table.For an example, let us create a tablemysql> create table PostMesssageDemo    - > (    - > UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    - > UserMessage varchar(100),    - > UserPost datetime    - > ); Query OK, 0 rows affected (0.60 sec)Now you can insert some records in the table using insert command.The query is as followsmysql> insert into PostMesssageDemo(UserMessage, UserPost) values('Software Developer', now()); Query OK, 1 row affected (0.17 sec) mysql> insert into PostMesssageDemo(UserMessage, UserPost) values('Software Developer', date_add(now(), interval 3 ... Read More

Connected and Disconnected Row Sets in JDBC

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

533 Views

A RowSet is a wrapper around a ResultSet Object. It can be connected, disconnected from the database and can be serialized. It maintains a JavaBean component by setting the properties. You can pass a RowSet object over the network. By default, the RowSet object is scrollable and updatable.A RowSet Object is of two typesConnected Row Sets: A connected RowSet object connects to the database using a JDBC driver. It establishes a connection with the database and, carries out the required operations. The connection is maintained until the RowSet object is closed.Disconnected Row Sets: A disconnected RowSet object connects to the ... Read More

LocalDateTime to LocalDate Method in Java

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

76 Views

The representation of the LocalDate can be obtained using the method toLocalDate() in the LocalDateTime class in Java. This method requires no parameters and it returns the LocalDate value of the LocalDateTime object.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.util.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime is: " + ldt);       System.out.println("The LocalDate representation is: " + ldt.toLocalDate());    } }OutputThe LocalDateTime is: 2019-02-18T23:15:30 The LocalDate representation is: 2019-02-18Now let us understand the above program.First ... Read More

Iterator Method of Java AbstractSequentialList Class

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

99 Views

The iterator() method of the AbstractSequentialList class iterates over the elements in this list and returns it.The syntax is as followsIterator iterator()To work with the AbstractSequentialList class in Java, you need to import the following packageimport java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList iterator() method in JavaExample Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; import java.util.Iterator; public class Demo {    public static void main(String[] args) {       AbstractSequentialList       absSequential = new LinkedList();       absSequential.add(10);       absSequential.add(25);       absSequential.add(60);       absSequential.add(70);       absSequential.add(195);       System.out.println("Elements ... Read More

Resolve Multi Update Only Works with Operators in MongoDB

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

840 Views

You can use $set operator for this. The syntax is as follows −db.yourCollectionName.update({ }, {'$set': "yourFieldName": "yourValue" }, false, true);To understand the above syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.unconditionalUpdatesDemo.insertOne({"ClientName":"Larry", "ClientAge":24}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8eb7372f684a30fbdfd557") } > db.unconditionalUpdatesDemo.insertOne({"ClientName":"Mike", "ClientAge":26}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8eb73f2f684a30fbdfd558") } > db.unconditionalUpdatesDemo.insertOne({"ClientName":"Sam", "ClientAge":27}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8eb7462f684a30fbdfd559") } > db.unconditionalUpdatesDemo.insertOne({"ClientName":"Carol", "ClientAge":29}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8eb7502f684a30fbdfd55a") }Display all documents from a ... Read More

Advertisements