MySQL Articles

Page 163 of 355

Counting voucher value total since the beginning of the month and year in MySQL

AmitDiwan
AmitDiwan
Updated on 12-Dec-2019 201 Views

For this, use MySQL MONTH() and YEAR() methods. Let us first create a table −mysql> create table DemoTable1562    -> (    -> VoucherValue int,    -> RechargeDate date    -> ); Query OK, 0 rows affected (1.40 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1562 values(149, '2019-10-21'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1562 values(199, '2019-10-13'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1562 values(399, '2018-10-13'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable1562 values(450, '2019-10-13'); Query OK, 1 row affected (0.20 sec)Display all ...

Read More

MySQL query to fetch multiple least values?

AmitDiwan
AmitDiwan
Updated on 12-Dec-2019 224 Views

For this, you can use a sub query along with MIN(). Let us first create a table−mysql> create table DemoTable    -> (    -> Name varchar(20),    -> Score int    -> ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', 56); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('John', 45); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values('John', 58); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Chris', 43); Query OK, 1 row affected (0.15 ...

Read More

What's the most efficient way to pull data from MySQL so that it is formatted with duplicate values

AmitDiwan
AmitDiwan
Updated on 12-Dec-2019 171 Views

For this, you can use GROUP_CONCAT(). Let us first create a table −mysql> create table DemoTable1561    -> (    -> StudentName varchar(20),    -> Title text    -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1561 values('Adam', 'Learning Java'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1561 values('Bob', 'Learning C'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1561 values('Adam', 'Learning Spring and Hibernate Framework'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1561 values('Carol', 'Learning MySQL from basic'); Query ...

Read More

Fix Error in MySQL syntax while creating a table column with name "index"?

AmitDiwan
AmitDiwan
Updated on 12-Dec-2019 922 Views

You can’t use the index as a column name because it is a reserved word. For this, you need to use backticks around the column name.If you will use a reserved word as the column name, you can see the following error−mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> index int    -> )ENGINE=MyISAM; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'int )ENGINE=MyISAM' at line 4Let us first ...

Read More

Display USD currency records with the correct format in MySQL

AmitDiwan
AmitDiwan
Updated on 12-Dec-2019 520 Views

Use FORMAT() in MySQL to display USD currency records in the correct form. Let us first create a table −mysql> create table DemoTable    -> (    -> Amount DECIMAL(15, 4)    -> ); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(90948484); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(1000000000); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(1535353536); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(773646463); Query OK, 1 row affected (0.20 sec)Display all records from ...

Read More

Shuffling column values with MySQL?

AmitDiwan
AmitDiwan
Updated on 12-Dec-2019 982 Views

To shuffle elements, you need to use ORDER BY RAND(). Let us first create a table −mysql> create table DemoTable1557    -> (    -> SubjectId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> SubjectName varchar(20)    -> ); Query OK, 0 rows affected (0.91 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1557(SubjectName) values('MySQL'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1557(SubjectName) values('MongoDB'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1557(SubjectName) values('Java'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1557(SubjectName) values('C'); Query OK, 1 row affected ...

Read More

Update MySQL table on INSERT command with triggers?

AmitDiwan
AmitDiwan
Updated on 12-Dec-2019 317 Views

Let us first create a table −mysql> create table DemoTable1    -> (    -> Id int,    -> FirstName varchar(20)    -> ); Query OK, 0 rows affected (0.52 sec)Here is the query to create second table −mysql> create table DemoTable2    -> (    -> EmployeeId int,    -> EmployeeName varchar(20)    -> ); Query OK, 0 rows affected (0.51 sec)Let us now create a trigger to update MySQL table on insert command −mysql>  DELIMITER // mysql>     CREATE TRIGGER updateDemoOnInsert    ->      AFTER INSERT ON DemoTable2    ->         FOR EACH ...

Read More

Quickly search for a string in MySQL database?

AmitDiwan
AmitDiwan
Updated on 12-Dec-2019 552 Views

Use FULLTEXT search to quickly search for a string. Let us first create a table −mysql> create table DemoTable1554    -> (    -> Title text    -> ); Query OK, 0 rows affected (0.63 sec)Here is the query to create full text search −mysql> create fulltext index faster_title on DemoTable1554(Title); Query OK, 0 rows affected, 1 warning (7.09 sec) Records: 0  Duplicates: 0  Warnings: 1Insert some records in the table using insert command −mysql> insert into DemoTable1554 values('John is working on MySQL database'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable1554 values('Adam Smith is working on ...

Read More

Display an error while inserting duplicate records in a MySQL table

AmitDiwan
AmitDiwan
Updated on 12-Dec-2019 436 Views

For this, you can use UNIQUE KEY. Let us first create a table −mysql> create table DemoTable1553    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> EmployeeName varchar(20),    -> EmployeeSalary int    -> ); Query OK, 0 rows affected (0.47 sec)Here is the query to add unique key −mysql> alter table DemoTable1553 add unique(EmployeeSalary); Query OK, 0 rows affected (0.53 sec) Records: 0  Duplicates: 0  Warnings: 0Insert some records in the table using insert command −mysql> insert into DemoTable1553(EmployeeName, EmployeeSalary) values('Chris', 45000); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1553(EmployeeName, EmployeeSalary) ...

Read More

Why does the update command in MySQL insist on using slanted single quotes?

AmitDiwan
AmitDiwan
Updated on 12-Dec-2019 130 Views

Use single quotes on string input value. If there is an identifier like table name or column name, then do not use single quotes (use backticks).Let us first create a table −mysql> create table DemoTable1552    -> (    -> `key` int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.82 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1552 values(101, 'Chris'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1552 values(102, 'David'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable1552 values(103, 'Mike'); Query OK, 1 row ...

Read More
Showing 1621–1630 of 3,547 articles
« Prev 1 161 162 163 164 165 355 Next »
Advertisements