Samual Sam has Published 2310 Articles

MySQL query to perform delete operation where id is the biggest?

Samual Sam

Samual Sam

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

200 Views

You can use ORDER BY DESC command with LIMIT 1 for this since we need to delete only a single ID.Let us first create a table −mysql> create table DemoTable (    UserId int,    UserName varchar(20) ); Query OK, 0 rows affected (0.57 sec)Insert records in the table using ... Read More

Can we add a column to a table from another table in MySQL?

Samual Sam

Samual Sam

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

2K+ Views

Yes, we can add a column to a table from another table. Let us first create two tables. The query to create a table is as follows −mysql> create table FirstTable    -> (    -> UserId int,    -> UserName varchar(20)    -> ); Query OK, 0 rows ... Read More

Which datatype is should I use to set a column for 5-star rating?

Samual Sam

Samual Sam

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

718 Views

You can use ENUM datatype for this. Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    UserRating ENUM('1', '2', '3', '4', '5') ); Query OK, 0 rows affected (0.54 sec)Insert records in the table using insert command −mysql> insert into ... Read More

Extracting only date from datetime field in MySQL and assigning it to PHP variable?

Samual Sam

Samual Sam

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

717 Views

You need to use DateTime class if you want to extract the only date from datetime field. The syntax is as follows −DateTime::createFromFormat("Y-m-d H:i:s", yourDateTimeValue)->format("yourFormatSpecifier");Now you can implement the above syntax in your PHP code to extract the only date from datetime field. The PHP code is as follows −$MySQLDataBaseDateTime ... Read More

How to select from a set of integers in MySQL?

Samual Sam

Samual Sam

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

241 Views

To select from a set of integers, you can use UNION. Following is the syntax −SELECT yourValue1 UNION SELECT yourValue2 UNION SELECT yourValue3 UNION SELECT yourValue4 . . . . NLet us implement the above syntax to select from a set of integers in MySQL −mysql> SELECT 1000 UNION SELECT 2000 ... Read More

How to track the order of insertion using Java collections?

Samual Sam

Samual Sam

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

274 Views

To track the order of insertion, you can use Map.Entry() in case of a Map. Let’s say we have the following LinkedHashMap −Mapmap = new LinkedHashMap(); map.put("Jack", 0); map.put("Tim", 1); map.put("David", 2); map.put("Tom", 3); map.put("Kevin", 4); map.put("Jeff", 5);Now, loop through Map.Entry and get the order of insertion correctly with Key ... Read More

MySQL order by from highest to lowest value?

Samual Sam

Samual Sam

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

3K+ Views

To order by from highest to lowest value, you can use ORDER BY DESC command −select *from yourTableName order by yourColumnName DESC;If you want the result from lowest to highest, you can use ORDER BY ASC command −select *from yourTableName order by yourColumnName ASC;Let us first create a table −mysql> ... Read More

How to use poll() in android ConcurrentLinkedDeque?

Samual Sam

Samual Sam

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

175 Views

Before getting into an example, we should know what ConcurrentLinkedDeque is, it is unbounded deque based on linked nodes. Multiple threads can access deque elements with safety.This example demonstrates about How to use poll() in android ConcurrentLinkedDequeStep 1 − Create a new project in Android Studio, go to File ⇒ ... Read More

How to use null value as key in Java HashMap

Samual Sam

Samual Sam

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

3K+ Views

Yes, you can set null as key in Java HashMap. For this, let’s first create a HashMap with key and value pair −Mapmap = new HashMap(); map.put("Football", "A"); map.put("Squash", "B"); map.put("Cricket", "C"); map.put("Hockey", "D"); map.put("Rugby", "E");Now, let’s add null value as key −map.put(null, "H");You can try to get the value ... Read More

What is the easiest way to store date in MySQL database?

Samual Sam

Samual Sam

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

266 Views

To store date in MySQL, use the STR_TO_DATE() method −insert into yourTableName values(STR_TO_DATE('yourDate', '%d/%m/%Y'));Let us first create a table −mysql> create table DemoTable (    AdmissionDate date ); Query OK, 0 rows affected (0.62 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(STR_TO_DATE('10/01/2013', '%d/%m/%Y')); Query OK, ... Read More

Advertisements