Found 4219 Articles for MySQLi

How to get the maximum value from strings with integers in MySQL?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

3K+ Views

You can use CAST() with MAX() for this. Since the string is filled with string and integer, fir example, “STU201”, therefore we need to use CAST().Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentBookCode varchar(200) ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentBookCode) values('STU201'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(StudentBookCode) values('STU202'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(StudentBookCode) values('STU203'); Query OK, 1 row affected (0.20 sec) mysql> ... Read More

How to use TIME type in MySQL?

Chandu yadav
Updated on 30-Jul-2019 22:30:25

186 Views

Let us first create a table. Within that we have set a column with type TIME to get the login time −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    LoginTime TIME NULL ); Query OK, 0 rows affected (0.69 sec)Insert records in the table using insert command −mysql> insert into DemoTable(LoginTime) values('12:34:45'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(LoginTime) values('13:56:01'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(LoginTime) values('04:12:23'); Query OK, 1 row affected (0.13 sec)Following is the query to display all records from the table using ... Read More

How to display the bit(1) fields in MySQL?

George John
Updated on 30-Jul-2019 22:30:25

611 Views

Let us first create a table. Here, our columns is of type bit(1) −mysql> create table DemoTable (    isCaptured bit(1) ); Query OK, 0 rows affected (1.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.29 sec)Following is the query to display all records from the table using select statement −mysql> select ... Read More

What does /* in MySQL means?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

385 Views

This is a type of comment. The /* is the beginning of a comment and */ is the end of comment.Let us implement and display how to create a commentmysql> /* This is the first MySQL Program */MySQL will ignore the above comment.Let us see an example. Here, we have written a comment with /* and */mysql> /*This table has information about person */ mysql> create table DemoTable (    PersonId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    PersonName varchar(20),    PersonAge int ); Query OK, 0 rows affected (0.58 sec)

How to count number of specific symbols in a row in MySQL?

George John
Updated on 30-Jul-2019 22:30:25

390 Views

You can use LENGTH() to count number of specific symbols in a row. Let us first create a table −mysql> create table DemoTable (    Value varchar(200) ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('?1234?6789?5656?324?'); Query OK, 1 row affected (0.17 sec)Following is the query to display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+----------------------+ | Value | +----------------------+ | ?1234?6789?5656?324? | ... Read More

Sort in MySQL and increment value?

Chandu yadav
Updated on 30-Jul-2019 22:30:25

318 Views

You can use update command along with a user-defined variable. Let us first create a table −mysql> create table DemoTable (    FirstName varchar(20),    Position int ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 100); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Robert', 120); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('David', 130); Query OK, 1 row affected (0.16 sec)Following is the query to display all records from the table using select statement −mysql> select *from DemoTable;This will produce ... Read More

How to convert date YYYYMMDD to YY-MM-DD in MySQL query?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

2K+ Views

To convert date YYYYMMDD to YY-MM-DD in MySQL, use the below syntax −select date_format(str_to_date(yourColumnName, '%Y%m%d'), '%Y-%m-%d') from yourTableName;Let us first create a table −mysql> create table DemoTable (    ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ClientProjectDeadline varchar(200) ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command. We have inserted dates in the YYYYMMDD format −mysql> insert into DemoTable(ClientProjectDeadline) values('20121221'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(ClientProjectDeadline) values('20190416'); Query OK, 1 row affected (0.53 sec) mysql> insert into DemoTable(ClientProjectDeadline) values('20160624'); Query OK, 1 row affected (0.20 sec) mysql> ... Read More

Display all records except one in MySQL

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

445 Views

You can use IN() to display all records except one in MySQL. Let us first create a table −mysql> create table DemoTable (    Id int,    FirstName varchar(20) ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Larry'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable values(10, 'Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(110, 'Robert'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(90, 'David'); Query OK, 1 row affected (0.20 sec)Following is the query ... Read More

How to get the greatest of two columns values in MySQL?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

223 Views

In order to get the greatest of two columns values in MySQL, you need to use GREATEST() function. Following is the syntax:select greatest(yourColumnName1, yourColumnName2) AS anyAliasName from yourTableName; Let us first create a table:mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Number1 int,    Number2 int ); Query OK, 0 rows affected (0.63 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable(Number1, Number2) values(1000, 10000); Query OK, 1 row affected (0.49 sec) mysql> insert into DemoTable(Number1, Number2) values(600, 900); Query OK, 1 row affected (0.12 sec) mysql> ... Read More

Query MySQL database to echo highest auto incremented number?

George John
Updated on 30-Jul-2019 22:30:25

65 Views

Let us first create a table with Id as auto_increment −mysql> create table DemoTable (    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    UserName varchar(20) ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(UserName) values('John'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(UserName) values('Larry'); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable(UserName) values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(UserName) values('Bob'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(UserName) values('Carol'); Query OK, 1 row affected ... Read More

Advertisements