Found 4378 Articles for MySQL

How to treat MySQL longtext as integer in MySQL query?

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

217 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 DemoTable values('9998888485775775757577578585'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('8888874757757757757757575675656'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('988757757574646'); Query OK, 1 row affected (0.09 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will produce the following ... Read More

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

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

476 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 a MySQL table.Exampleimport java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; public class InsertOneColumnDemo {    public static void main(String[] args) {       Connection con = null;       PreparedStatement ps = null;       try {          con = DriverManager.getConnection("jdbc:mysql://localhost:3306/web?" + "useSSL=false", "root", "123456");   ... Read More

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

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

2K+ 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 (0.54 sec) mysql> insert into DemoTable values(102, 'David'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(103, 'Mike'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will produce the following output −+------+-------+ | Id   ... Read More

Sort character values from a column mixed with character and numbers in MySQL?

AmitDiwan
Updated on 26-Feb-2020 05:19:51

143 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Code varchar(20)    -> ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('J23'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('C13'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('A61'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('D56'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will produce the following ... Read More

Adding a new NOT NULL column to an existing table with records

AmitDiwan
Updated on 26-Feb-2020 05:20:44

178 Views

To add a new NOT NULL column to an already created table, use ALTER command. 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 (0.60 sec)Following is the query to add a new NOT NULL column to an existing table −mysql> alter table DemoTable add column StudentAge int NOT NULL; Query OK, 0 rows affected (0.52 sec) Records: 0 Duplicates: 0 Warnings: 0Insert some records in the table using insert command −mysql> insert into DemoTable(StudentName, ... Read More

How to display first day and last day of the month from date records in MySQL?

AmitDiwan
Updated on 18-Dec-2019 06:27:28

209 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> DueDate date    -> ); Query OK, 0 rows affected (0.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-11'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('2019-04-19'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+------------+ | DueDate    | +------------+ | 2019-01-11 | | 2019-04-19 | +------------+ 2 rows in set (0.00 sec)Following is the query to display ... Read More

MySQL query to find duplicate tuples and display the count?

AmitDiwan
Updated on 26-Feb-2020 05:22:43

460 Views

To find duplicate tuples, use GROUP BY HAVING clause. Let us first create a table −mysql> create table DemoTable    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.80 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(101, 'David'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(101, 'Mike'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(100, 'Carol'); Query OK, 1 row affected (0.17 sec) ... Read More

SUM corresponding duplicate records in MySQL

AmitDiwan
Updated on 26-Feb-2020 05:23:52

514 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> StudentName varchar(20),    -> StudentMarks int    -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 50); Query OK, 1 row affected (0.61 sec) mysql> insert into DemoTable values('David', 70); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('Chris', 80); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('David', 90); Query OK, 1 row affected (0.24 sec)Display all records from the table using select statement −mysql> ... Read More

Is it okay to store double and date in VARCHAR with MySQL?

AmitDiwan
Updated on 26-Feb-2020 05:24:46

161 Views

Yes, you can store double and date in VARCHAR. Let us first create a table −mysql> create table DemoTable    -> (    -> Amount varchar(20),    -> JoiningDate varchar(20)    -> ); Query OK, 0 rows affected (0.96 sec)Insert some records in the table using insert command. We are inserting varchar double and date values −mysql> insert into DemoTable values('150.50', 'Oct 10, 2019'); Query OK, 1 row affected (0.91 sec) mysql> insert into DemoTable values('173.45', 'Sept 11, 2018'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('173.90', 'Jan 01, 2017'); Query OK, 1 row affected (0.16 ... Read More

How do I drop a primary key in MySQL?

AmitDiwan
Updated on 18-Dec-2019 06:14:41

421 Views

To drop a primary key, use ALTER at first to alter the table. With that, use DROP to drop the key as in the belowSyntaxalter table yourTableName drop primary key;Let us first create a table −mysql> create table DemoTable    -> (    -> StudentId int NOT NULL,    -> StudentName varchar(20),    -> StudentAge int,    -> primary key(StudentId)    -> ); Query OK, 0 rows affected (0.48 sec)Here is the query to check the description of table −mysql> desc DemoTable;This will produce the following output−+-------------+-------------+------+-----+---------+-------+ | Field       | Type        | Null | ... Read More

Advertisements