AmitDiwan has Published 10744 Articles

How to fetch only a single result from a table in Java-MySQL?

AmitDiwan

AmitDiwan

Updated on 26-Feb-2020 05:04:00

3K+ Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (1.37 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(101, 'Chris'); Query OK, 1 row affected ... Read More

How to insert only a single column into a MySQL table with Java?

AmitDiwan

AmitDiwan

Updated on 26-Feb-2020 05:03:06

583 Views

Use INSERT INTO statement in the Java-MySQL connection code to insert a column.Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.54 sec)Here is the Java code to insert only a single column into ... Read More

How to treat MySQL longtext as integer in MySQL query?

AmitDiwan

AmitDiwan

Updated on 26-Feb-2020 05:02:08

303 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Value longtext    -> ); Query OK, 0 rows affected (0.94 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('778437437447488487476464644433334'); Query OK, 1 row affected (0.18 sec) mysql> insert into ... Read More

What would happen if we run SELECT WHERE columnName = zero in MySQL?

AmitDiwan

AmitDiwan

Updated on 25-Feb-2020 13:21:35

115 Views

The following syntax will fetch all the values from the column −select * from yourTableName where yourColumnName=0;Let us first create a table −mysql> create table DemoTable1791      (      FirstName varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert ... Read More

MySQL query to fetch records from a range of months?

AmitDiwan

AmitDiwan

Updated on 25-Feb-2020 13:19:16

188 Views

Let us first create a table −mysql> create table DemoTable1795      (      Name varchar(20),      DueDate date      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1795 values('John', '2018-07-21'); Query OK, 1 row affected ... Read More

How to auto increment with 1 after deleting data from a MySQL table?

AmitDiwan

AmitDiwan

Updated on 25-Feb-2020 13:18:07

749 Views

For this, you can use TRUNCATE TABLE command. Let us first create a table −mysql> create table DemoTable1796      (      StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,      StudentName varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using ... Read More

UNIX_TIMESTAMP with date in MySQL query to fetch records after a specific date in different format?

AmitDiwan

AmitDiwan

Updated on 25-Feb-2020 13:12:18

316 Views

For this, you can use STR_TO_DATE(), since we have date records in the following format: 21/11/2019.Let us first create a table −mysql> create table DemoTable1808      (      AdmissionDate varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command ... Read More

Update MySQL table column by matching date using date() function?

AmitDiwan

AmitDiwan

Updated on 25-Feb-2020 13:08:00

492 Views

Following is the syntax to match date with date() function and updating a column −update yourTableName set yourColumnName=yourValue where date(yourColumnName)=curdate();Let us first create a table −mysql> create table DemoTable1816      (      Name varchar(20),      JoiningDate datetime      ); Query OK, 0 rows affected (0.00 sec)Insert ... Read More

Fetch how many people are registering on the current date with MySQL

AmitDiwan

AmitDiwan

Updated on 25-Feb-2020 13:06:28

169 Views

For this, you can use COUNT() along with GROUP BY MONTH(). To match with the current date, use CURRENT_DATE(). The current date is as follows −mysql> select curdate() ; +------------+ | curdate()  | +------------+ | 2019-11-30 | +------------+ 1 row in set (0.00 sec)Let us first create a table −mysql> ... Read More

Check for NULL or empty variable in a MySQL stored procedure

AmitDiwan

AmitDiwan

Updated on 25-Feb-2020 13:02:51

6K+ Views

To check for NULL or empty variable, use the IF condition. Let us create a stored procedure −mysql> delimiter // mysql> create procedure checkingForNullDemo(Name varchar(20))      begin      if Name is NULL OR Name='' then      select 'Adam Smith';      else      select Name;   ... Read More

Advertisements