Daniol Thomas has Published 197 Articles

How can I count the number of days in MySQL?

Daniol Thomas

Daniol Thomas

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

444 Views

Let us first create a table with one column as datetime and another wherein the days are stored:mysql> create table DemoTable (    ShippingDate datetime,    CountOfDate int ); Query OK, 0 rows affected (0.52 sec)Following is the query to insert some records in the table using insert command:mysql> insert ... Read More

How to use COUNT(*) to return a single row instead of multiple?

Daniol Thomas

Daniol Thomas

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

837 Views

You need to use GROUP BY with COUNT(*) for this to group the values and display the count eliminating multiple values. Let us first create a table:mysql> create table DemoTable (Value int); Query OK, 0 rows affected (0.55 sec)Following is the query to insert some records in the table using ... Read More

Get today's date in (YYYY-MM-DD) format in MySQL?

Daniol Thomas

Daniol Thomas

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

3K+ Views

To get today’s date in (YYYY-MM-DD) format in MySQL, you can use CURDATE().Following is the query to get the current date:mysql> SELECT CURDATE();This will produce the following output:+------------+ | CURDATE() | +------------+ | 2019-04-09 | +------------+ 1 row in set (0.00 sec)You can also use NOW() for this. Following ... Read More

MySQL query to get substrings (only the last three characters) from strings?

Daniol Thomas

Daniol Thomas

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

279 Views

For this, you can use SUBSTR() method. Let us first create a table:mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstName varchar(20)); Query OK, 0 rows affected (1.31 sec)Following is the query to insert some records in the table using insert command:mysql> insert into ... Read More

Period between() method in Java

Daniol Thomas

Daniol Thomas

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

4K+ Views

The Period between two dates can be obtained using the between() method in the Period class in Java. This method requires two parameters i.e. the start date and the end date and it returns the Period between these two dates.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; ... Read More

Period negated() method in Java

Daniol Thomas

Daniol Thomas

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

81 Views

An immutable copy of a Period where all the Period elements are negated can be obtained using the method negated() in the Period class in Java. This method requires no parameters and it returns the Period elements after negating them.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; ... Read More

How to compare DateTime Column with only Date not time in MySQL?

Daniol Thomas

Daniol Thomas

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

2K+ Views

To compare DateTime column with only Date, you need to use the Date() method. Following is the syntax. Below, you need to date in the 'yourDateValue':select *from yourTableName where Date(yourColumnName)='yourDateValue';Let us first create a table:mysql> create table DemoTable (    ArrivalTime datetime ); Query OK, 0 rows affected (0.74 sec)Following ... Read More

MySQL query to delete a record with the lowest ID?

Daniol Thomas

Daniol Thomas

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

903 Views

To delete record with the lowest id, you can use the following syntax:delete from yourTableName order by yourColumnName limit 1;Let us first create a table:mysql> create table DemoTable (    Id int,    Name varchar(20) ); Query OK, 0 rows affected (0.75 sec)Following is the query to insert records in ... Read More

Write an example JDBC program demonstrating the batch processing with PreparedStatement object?

Daniol Thomas

Daniol Thomas

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

187 Views

Grouping related SQL statements into a batch and executing/submitting them at once is known as batch processing. The Statement interface provides methods to perform batch processing such as addBatch(), executeBatch(), clearBatch().Follow the steps given below to perform batch updates using the PreparedStatement object:Register the driver class using the registerDriver() method ... Read More

Alter row_format to dynamic in MySQL?

Daniol Thomas

Daniol Thomas

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

1K+ Views

To alter row_format to dynamic in MySQL, following is the syntax:ALTER TABLE yourTableName ROW_FORMAT=DYNAMIC;Let us first create a table:mysql> create table DemoTable (    CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    CustomerName varchar(200),    CustomerAge int,    CustomerAddress varchar(200) ); Query OK, 0 rows affected (0.73 sec)Let us check ... Read More

Advertisements