Found 4219 Articles for MySQLi

Get MAX and MIN values along with their row id in MySQL?

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

1K+ Views

You can use aggregate function MAX() and MIN() for this.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.89 sec)Insert records in the table using insert command −mysql> insert into DemoTable(Number1, Number2) values(67, 45); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(Number1, Number2) values(90, 40); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(Number1, Number2) values(80, 43); Query OK, 1 row affected (0.48 sec)Display all records from the table using select ... Read More

How can I modify an existing column's data type?

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

131 Views

To modify an existing column’s data type, you can use MODIFY. Let us first create a table −mysql> create table DemoTable    (    ClientId varchar(100),    ClientName varchar(100),    ClientAge int,    ClientProjectDeadline timestamp,    ClientCountryName varchar(100),    isMarried boolean,    ClientNumber bigint    ); Query OK, 0 rows affected (0.70 sec)Check the description of table −mysql> desc DemoTable;This will produce the following output −+-----------------------+--------------+------+-----+---------+-------+ | Field                 | Type         | Null | Key | Default | Extra | +-----------------------+--------------+------+-----+---------+-------+ | ClientId             ... Read More

How to update all dates in a Table?

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

90 Views

You can use UPDATE with DATE_ADD() to update all dates. Let us first create a table −mysql> create table DemoTable    (    ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ClientProjectDueDate date    ); Query OK, 0 rows affected (1.19 sec)Insert records in the table using insert command −mysql> insert into DemoTable(ClientProjectDueDate) values('2018-01-21'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(ClientProjectDueDate) values('2019-03-25'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(ClientProjectDueDate) values('2013-11-01'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(ClientProjectDueDate) values('2015-06-14'); Query OK, 1 row affected (0.23 sec)Display all records from ... Read More

Order by selected record in MySQL?

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

111 Views

You can use a CASE statement for this. Let us first create a table −mysql> create table DemoTable    (    Number int    ); Query OK, 0 rows affected (0.71 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(490); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable values(310); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(540); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(123); Query OK, 1 row affected (0.60 sec) mysql> insert into DemoTable values(1230); Query OK, 1 row affected (0.15 sec) mysql> ... Read More

MySQL query to count frequency of students with the same age?

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

837 Views

You can use COUNT(*) along with GROUP BY for this. Let us first create a table −mysql> create table DemoTable    (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentAge int    ); Query OK, 0 rows affected (0.59 sec)Insert records in the table using insert command −mysql> insert into DemoTable(StudentAge) values(16); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(StudentAge) values(17); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(StudentAge) values(18); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentAge) values(17); Query OK, 1 row affected (0.13 sec) mysql> insert into ... Read More

MySQL order from a different starting value?

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

105 Views

Let us first create a table −mysql> create table DemoTable    (    ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ClientName varchar(30)    ); Query OK, 0 rows affected (0.74 sec)Insert records in the table using insert command −mysql> insert into DemoTable(ClientName) values('John'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(ClientName) values('Chris'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(ClientName) values('Robert'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(ClientName) values('David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(ClientName) values('Bob'); Query OK, 1 row affected (0.15 sec) mysql> ... Read More

Order By date ASC in MySQL?

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

258 Views

You can use STR_TO_DATE() function. Let us first create a table −mysql> create table DemoTable    (    AdmissionDate varchar(200)    ); Query OK, 0 rows affected (1.19 sec)Insert records in the table using insert command −mysql> insert into DemoTable values('12-01-2019'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('14-12-2016'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('26-04-2018'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable values('31-05-2013'); Query OK, 1 row affected (0.30 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will produce the ... Read More

How to create a table with date column?

George John
Updated on 02-Sep-2023 02:12:57

86K+ Views

To create a table with only date column, you can use DATE type. Let us first create a table −mysql> create table DemoTable    (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(20),    StudentAdmissionDate DATE    ); Query OK, 0 rows affected (0.47 sec)Insert records in the table using INSERT command −mysql> insert into DemoTable(StudentName, StudentAdmissionDate) values('Chris', now()); Query OK, 1 row affected, 1 warning (0.12 sec) mysql> insert into DemoTable(StudentName, StudentAdmissionDate) values('Robert', curdate()); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(StudentName, StudentAdmissionDate) values('David', '2019-05-21'); Query OK, 1 row affected (0.16 sec)Display all ... Read More

How to select the maximum value of a column in MySQL?

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

10K+ Views

You can use ORDER BY clause or aggregate function MAX() to select the maximum value.Using ORDER BYFollowing is the syntax −select yourColumnName from yourTableName order by yourColumnName desc limit 0, 1;Let us first create a table −mysql> create table DemoTable    (    Number int    ); Query OK, 0 rows affected (0.52 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(790); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(746); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(480); Query OK, 1 row affected (0.15 sec) mysql> insert into ... Read More

Combine MySQL UPDATE STATEMENTS?

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

185 Views

You can use a CASE statement for this. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(20)    ); Query OK, 0 rows affected (1.11 sec)Insert records in the table using insert command −mysql> insert into DemoTable(Name) values('John'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable(Name) values('Carol'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Name) values('David'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will produce the following ... Read More

Advertisements