Found 4219 Articles for MySQLi

Delete URLs with specific domains from MySQL database?

AmitDiwan
Updated on 08-Nov-2019 10:39:25

225 Views

To delete URLs with specific domains, use DELETE and LIKE clause.Let us first create a table −mysql> create table DemoTable1361     -> (     -> URL text     -> ) ; Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1361 values('Https://www.google.com//?id=1'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1361 values('Https://www.facebook.com//?id=2&name=John'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1361 values('Https://www.yahoo.com//?id=3'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable1361 values('Https://www.google.com//?id=1'); Query OK, 1 row affected (0.16 sec)Display all records from ... Read More

Get current year in MySQL WHERE clause?

AmitDiwan
Updated on 08-Nov-2019 10:37:28

608 Views

To get current year, use YEAR() along with CURDATE(). Let us first create a table −mysql> create table DemoTable1360     -> (     -> JoiningYear int     -> )     -> ; Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1360 values(1998); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1360 values(2018); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1360 values(2016); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1360 values(2019); Query OK, 1 row affected (0.13 sec) mysql> ... Read More

Using backticks in CONTACT() gives an error in MySQL

AmitDiwan
Updated on 08-Nov-2019 10:35:10

88 Views

Do not use backticks, you can use single quotes in CONCAT(). Following is the syntax −select concat(yourColumnName1, ' ', yourColumnName2) from yourTableName;Let us first create a table −mysql> create table DemoTable1359     -> (     -> Id int,     -> Name varchar(20)     -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1359 values(101, 'Chris'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1359 values(102, 'Adam'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1359 values(103, 'Mike'); Query OK, 1 row ... Read More

Sum values in MySQL from similar day records

AmitDiwan
Updated on 05-Nov-2019 10:19:27

694 Views

Use GROUP BY and DATE() for this. Let us first create a table −mysql> create table DemoTable1358     -> (     -> PurchaseDate datetime,     -> ProductPrice int     -> ); Query OK, 0 rows affected (1.59 sec)Insert some records in the table using insert command. Here, we have inserted date records, with some records with similar dates −mysql> insert into DemoTable1358 values('2019-09-20 12:34:00', 450); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable1358 values('2019-09-21 11:00:00', 1050); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable1358 values('2018-09-21 02:10:00', 2050); Query OK, 1 ... Read More

Display the result with not null value first and then with null value in MySQL

AmitDiwan
Updated on 05-Nov-2019 10:18:06

274 Views

Let us first create a table −mysql> create table DemoTable1357     -> (     -> StudentName varchar(40),     -> StudentCountryName varchar(30)     -> ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1357 values('Chris', 'US'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1357 values('David', NULL); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1357 values('David', 'AUS'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1357 values('Carol', NULL); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1357 values('Mike', ... Read More

Alter a table column from VARCHAR to NULL in MySQL

AmitDiwan
Updated on 05-Nov-2019 10:15:48

409 Views

To alter, use the ALTER command with CHANGE as in the below syntax −alter table yourTableName change yourColumnName yourColumnName datatype NULL DEFAULT NULL;Let us first create a table −mysql> create table DemoTable1356     -> (     -> FirstName varchar(30)     -> ); Query OK, 0 rows affected (0.56 sec)Let us implement the above syntax to alter a table column to NULL −mysql> alter table DemoTable1356 change FirstName FirstName varchar(30) NULL DEFAULT NULL; Query OK, 0 rows affected (0.17 sec) Records: 0  Duplicates: 0  Warnings: 0Insert some records in the table using insert command −mysql> insert into DemoTable1356 ... Read More

MySQL query to return all items in a single row

AmitDiwan
Updated on 05-Nov-2019 10:14:31

859 Views

For this, use GROUP_CONCAT(). Let us first create a table−mysql> create table DemoTable1355     -> (     -> Location text     -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1355 values('E:'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1355 values('AllPrograms'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1355 values('ChatApplicationInJava'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable1355 values('MainFolder'); Query OK, 1 row affected (0.23 sec)Display all records from the table using select statement −mysql> select * ... Read More

Fix Error 1136: Column count doesn't match value count at row 1?

AmitDiwan
Updated on 05-Nov-2019 10:13:16

2K+ Views

You may get tis value, if you are missing the value for auto_increment column. The error is as follows −mysql> insert into DemoTable1353 values('Chris', 23); ERROR 1136 (21S01): Column count doesn't match value count at row 1You need to provide the value for auto_increment or leave it to automatic generation.Let us see an example and create a table −mysql> create table DemoTable1353     -> (     -> Id int NOT NULL AUTO_INCREMENT,     -> Name varchar(20),     -> Age int,     -> PRIMARY KEY(Id)     -> ); Query OK, 0 rows affected (0.52 sec)Insert ... Read More

Cast one of the values in MySQL and perform division with the other?

AmitDiwan
Updated on 05-Nov-2019 09:35:06

122 Views

For this, at first, use CAST(). Let us first create a table −mysql> create table DemoTable1352     -> (     -> Value1 int,     -> Value2 int     -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command−mysql> insert into DemoTable1352 values(10, 30); Query OK, 1 row affected (0.42 sec) mysql> insert into DemoTable1352 values(40, 60); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1352 values(110, 130); Query OK, 1 row affected (0.18 sec)Display all records from the table using select statement−mysql> select * from DemoTable1352; This ... Read More

Display only the duplicate column names appearing atleast thrice in MySQL

AmitDiwan
Updated on 05-Nov-2019 09:33:43

60 Views

Use HAVING COUNT() for this. Let us first create a table −mysql> create table DemoTable1351     -> (     -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,     -> StudentName varchar(40)     -> ); Query OK, 0 rows affected (1.08 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1351(StudentName) values('Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1351(StudentName) values('Bob'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1351(StudentName) values('Bob'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1351(StudentName) values('David'); Query OK, 1 row affected (0.11 ... Read More

Advertisements