Found 4219 Articles for MySQLi

Need to populate autocomplete with records on the basis of first and last name of schools in MySQL?

AmitDiwan
Updated on 09-Oct-2019 10:30:14

58 Views

To populate autocomplete, use the LIKE clause in MySQL. Let us first create a table −mysql> create table DemoTable (    SchoolName varchar(100) ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Horce Greeley'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Conestoga Senior'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Adlai E.Stevenson'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Thomas Jefferson'); Query OK, 1 row affected (0.07 sec)Display all records from the table using select statement :mysql> ... Read More

Group by one column and display corresponding records from another column with a separator in MySQL

AmitDiwan
Updated on 09-Oct-2019 10:28:07

1K+ Views

For this, use GROUP_CONCAT() along with GROUP BY. Here, the GROUP_CONCAT() is used to concatenate data from multiple rows into one field.Let us first create a table −mysql> create table DemoTable (    PlayerId int,    ListOfPlayerName varchar(30) ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(101, 'David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(100, 'Bob'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(100, 'Sam'); Query ... Read More

Display NULL and NOT NULL records except a single specific value in MySQL

AmitDiwan
Updated on 07-Oct-2019 13:04:54

128 Views

To display NULL records, use IS NULL in MySQL. To ignore a single value, use the != operator , which is an alias of the operator.Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    PlayerName varchar(40) ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −p>mysql> insert into DemoTable(PlayerName) values('Adam'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(PlayerName) values(NULL); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(PlayerName) values('Sam'); Query OK, 1 row affected (0.13 sec) ... Read More

MySQL throws an error when the table name “match” is not surrounded by single quotes?

AmitDiwan
Updated on 07-Oct-2019 13:02:44

151 Views

Do not use single quotes. You need to use backticks around the table name match, since it is a reserved name in MySQL. Following is the error that occurs :mysql> select *from match; 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 'match' at line 1Let us first create a table and fix the occurrence of the above error using backticks around the reserved word match, used here as table name −mysql> create table `match` (    Id int NOT ... Read More

Fix MySQL ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key

AmitDiwan
Updated on 07-Oct-2019 12:56:00

11K+ Views

To fix this error, you need to add PRIMARY KEY to auto_increment field. Let us now see how this error occurs −Here, we are creating a table and it gives the same error −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT,    StudentName varchar(40),    StudentAge int ); ERROR 1075 (42000) : Incorrect table definition; there can be only one auto column and it must be defined as a keyTo solve the above error, you need to add PRIMARY KEY with AUTO_INCREMENT. Let us first create a table −mysql> create table DemoTable (    StudentId int NOT ... Read More

Change only dates, ignoring time records in MySQL

AmitDiwan
Updated on 06-Jul-2020 09:17:34

48 Views

To change only dates, not time, use the MySQL INTERVAL and YEAR. Since, we will be updating the records, therefore, use UPDATE and set a new value with INTERVAL.Let us see an example and create a table −mysql> create table DemoTable (    DueDate datetime ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2017-08-12 10 :30 :45'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('2015-09-21 12 :00 :00'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('2018-12-31 11 :45 :56'); Query ... Read More

Get Nth weekday of the month from a column with DATE records in MySQL

AmitDiwan
Updated on 07-Oct-2019 12:51:19

198 Views

We need to find the weekday i.e. week 1 from date 1 to 7, week 2 from date 8 to 14, etc. To get the day, use DAY() function in MySQL. Set the conditions to get the weekday (number) using CASE statement.Let us now see an example and create a table −mysql> create table DemoTable (    AdmissionDate date ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-09-12'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('2019-09-06'); Query OK, 1 row affected (0.16 sec) mysql> ... Read More

How can I select every alternative row and display in descending order in SQL?

AmitDiwan
Updated on 07-Oct-2019 12:45:42

3K+ Views

To fetch every alternative row, use MOD() under WHERE. Then use ORDER BY DESC to display the result in descending order −select *from yourTableName where mod(yourColumnName, 2)=1 order by yourColumnName DESC;Let us first create a table −mysql> create table DemoTable (    UniqueId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ClientName varchar(40),    ClientAge int ); Query OK, 0 rows affected (1.02 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ClientName, ClientAge) values('Chris', 34); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable(ClientName, ClientAge) values('Tom', 45); Query OK, 1 row affected (0.19 sec) mysql> ... Read More

Select all email addresses beginning with 5 numeric characters (regular expression) in MySQL

AmitDiwan
Updated on 07-Oct-2019 12:41:17

160 Views

To get the email addresses beginning with 5 numeric characters, the optional solution is to use REGEXP −select *from yourTableName where yourColumnName regexp "^[0-9]{5}";Let us first create a table −mysql> create table DemoTable (    UserEmailAddress varchar(100) ); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('6574John@gmail.com'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Carol23456@gmail.com'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('98989Chris_45678@gmail.com'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Mike12@gmail.com'); Query OK, 1 row affected (0.43 ... Read More

Get specific value of cell in MySQL

AmitDiwan
Updated on 07-Oct-2019 12:39:36

1K+ Views

Let us first create a table −mysql> create table DemoTable (    Name varchar(40),    Score int ); Query OK, 0 rows affected (0.72 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris Brown', 78); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('John Doe', 88); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Carol Taylor', 98); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('David Miller', 80); Query OK, 1 row affected (0.68 sec)Display all records from the table using select statement −mysql> select *from ... Read More

Advertisements