AmitDiwan has Published 10740 Articles

Shifting values of rows in MySQL to change the existing id values for existing rows?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 07:25:47

509 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(20)    -> ); Query OK, 0 rows affected (1.07 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentName) values('Chris'); Query ... Read More

MySQL query to delete last two words from every column value

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 07:20:25

207 Views

For this, you can use the LEFT() function from MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(10)    -> ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); ... Read More

Can we use the word user for a MySQL table?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 07:17:57

373 Views

You cannot use “user” for a MySQL table because it is a reserved word in MySQL. You can change the name from user to users or something else or you can use backticks around the user word.The word user can be used to create a user or can select a ... Read More

MySQL Select where timestamp is in the current hour?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 07:15:06

262 Views

For this, you can use CURTIME(). Let us first create a table −mysql> create table DemoTable    -> (    -> ArrivalTime timestamp    -> ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-10-26 17:55:55'); Query OK, 1 ... Read More

How to declare a variable inside a procedure in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 07:13:15

2K+ Views

You can use the DECLARE command to declare a variable inside a MySQL procedure. Let us create a stored procedure in MySQL −mysql> DELIMITER // mysql> CREATE PROCEDURE DECLARE_VARIABLE_DEMO(IN value int)    -> BEGIN    -> DECLARE searchValue int;    -> set searchValue=value;    -> if searchValue=10 then    -> ... Read More

Where we should close a connection in JDBC and MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 07:11:39

2K+ Views

You need to close connection in finally block. Following is the Java code to close connection in JDBC and MySQL −import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; public class CloseConnectionDemoInFinallyBlock {    public static void main(String[] args) {       String JDBCURL = "jdbc:mysql://localhost:3306/web?useSSL=false";       Connection ... Read More

Filtering data in a table for a required condition to eliminate a specific record with MySQL

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 07:06:16

125 Views

For this, you can use NOT LIKE operator. Let us first create a table −mysql> create table DemoTable    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(20),    -> StudentAdmissionYear varchar(20)    -> ); Query OK, 0 rows affected (1.22 sec)Insert some records ... Read More

MySQL query to find same value on multiple fields with LIKE operator?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 07:02:11

580 Views

Let us first create a table −mysql> create table DemoTable    ->    -> (    -> StudentName varchar(20),    -> StudentSubject varchar(20)    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', 'MySQL'); Query OK, 1 ... Read More

Fetch some words from the left in MySQL

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:59:37

124 Views

For this, use LEFT in MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> Title text    -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Java database connectivity to MySQL ... Read More

Difference between intvalue='1' and intvalue=1 in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:58:34

118 Views

You need to use intvalue=1. The statement intvalue=’1’ is internally converted to cast(‘1’ as int) by MySQL.Let us first create a table −mysql> create table DemoTable1566    -> (    -> intvalue int    -> ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert ... Read More

Advertisements