Select 5 Random Rows from the 20 Most Recent Rows in MySQL

Sharon Christine
Updated on 30-Jun-2020 13:22:49

499 Views

For random, use RAND() method. And for limit on rows, use the LIMIT() method.Let us first create a table −mysql> create table DemoTable    -> (    -> ShippingDate datetime    -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-01'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('2019-01-03'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2019-01-05'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-01-07'); Query OK, 1 row affected (0.11 sec) ... Read More

Subtraction of Multi-Byte BCD Numbers in 8085

Ankith Reddy
Updated on 30-Jun-2020 13:22:44

649 Views

Now let us see a program of Intel 8085 Microprocessor. In this program we will see how to subtract multi-Byte BCD numbers.Problem StatementWrite 8085 Assembly language program to subtract two multi-Byte BCD numbers.DiscussionThe numbers are stored into memory, and one additional information is stored. It will show us the Byte count of the multi-Byte BCD number. Here we are choosing 3-Byte BCD numbers. They are stored at location 8001H to 8003H, and another number is stored at location 8004H to 8006H. The location 8000H is holding the Byte count. In this case the Byte count is 03H.For the subtraction we ... Read More

MySQL Query to Select Date from Timestamp

karthikeya Boyini
Updated on 30-Jun-2020 13:21:07

440 Views

Let us first create a table. One of the column is a timestamp −mysql> create table DemoTable    -> (    -> CustomerName varchar(100),    -> CustomerShippingDate timestamp    -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', '2019-01-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('David', '2019-03-01'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('Robert', '2019-06-04'); Query OK, 1 row affected (0.25 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will ... Read More

MySQL Query to Find a Value Appearing More Than Once

Rama Giri
Updated on 30-Jun-2020 13:20:19

532 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> value int    -> ); Query OK, 0 rows affected (0.82 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable values(30); Query OK, 1 row affected (0.24 sec) ... Read More

Get First Element in Android ConcurrentLinkedDeque

karthikeya Boyini
Updated on 30-Jun-2020 13:19:46

152 Views

Before getting into example, we should know what ConcurrentLinkedDequeis, it is unbounded deque based on linked nodes. Multiple threads can access deque elements with safety.This example demonstrate about How to get first element in android ConcurrentLinkedDequeStep 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 text view to showConcurrentLinkedDequeelements.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import ... Read More

Compare Two Tables and Return Missing IDs Using MySQL Left Outer Join

Samual Sam
Updated on 30-Jun-2020 13:19:35

900 Views

To compare two tables and return missing ids, you need to use MySQL LEFT OUTER JOIN.Let us create a table with sample fields and then we will insert records. The query to create the first table −First_Tablemysql> create table First_Table    -> (    -> Id int    -> ); Query OK, 0 rows affected (0.88 sec)Now insert some records in the table using insert command. The query is as follows −mysql> insert into First_Table values(1); Query OK, 1 row affected (0.68 sec) mysql> insert into First_Table values(2); Query OK, 1 row affected (0.29 sec) mysql> insert into First_Table values(3); ... Read More

Select All Rows Except From Today in MySQL

Kumar Varma
Updated on 30-Jun-2020 13:19:19

529 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(100),    -> DueDate datetime    -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command. Let’s say the current date is “2019-07-03” −mysql> insert into DemoTable values('Chris', '2019-06-24'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Chris', '2018-01-01'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Robert', '2019-07-03'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('Carol', '2019-08-03'); Query OK, 1 row affected (0.22 ... Read More

Get Element Based on Index in Android CopyOnWriteArrayList

Samual Sam
Updated on 30-Jun-2020 13:19:16

458 Views

Before getting into example, we should know what CopyOnWriteArrayListis. It is a thread-safe variant of ArrayList and operations add, set, and so on by making a fresh copy of the underlying array.This example demonstrate about How to get element based on index in android CopyOnWriteArrayListStep 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 text view to showCopyOnWriteArrayListelements.Step 3 − Add the following code to ... Read More

Find Size of ArrayBlockingQueue in Android

karthikeya Boyini
Updated on 30-Jun-2020 13:18:42

110 Views

Before getting into example, we should know what arrayblockingqueue is, it travels FIFO manner and first element going to live longest period of time and last element of the queue going to live short period of the time.This example demonstrate about How to find size of ArrayBlockingQueue in androidStep 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 text view to showArrayBlockingQueue elements.Step 3 − ... Read More

Select Return Value from MySQL Prepared Statement

Rama Giri
Updated on 30-Jun-2020 13:17:20

889 Views

Let us create a stored procedure and select return value from MySQL prepared statement −mysql> DELIMITER // mysql> CREATE PROCEDURE return_value()    -> BEGIN    ->   SET @returnQuery= 'SELECT 98 INTO @value';    ->   PREPARE stmt FROM @returnQuery;    ->   EXECUTE stmt;    -> END    -> // Query OK, 0 rows affected (0.20 sec) mysql> DELIMITER ;Call stored procedure using CALL command.mysql> call return_value(); Query OK, 1 row affected (0.07 sec)Display value using select statement −mysql> select @value;outputThis will produce the following output −+--------+ | @value | +--------+ |     98 | +--------+ 1 row in set (0.00 sec)

Advertisements