Found 4219 Articles for MySQLi

How to get the date between TODAY and TODAY-7”?

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

6K+ Views

To get the date between dates, you need to use. Here, we are getting the dates between today and today-7 days −select *from yourTableName where DATE(yourColumnName) > (NOW() - INTERVAL 7 DAY);Note : Let’s say the current date is '2019-06-02’ Let us first create a table.mysql> create table DemoTable    (    LoginDate date    ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2018-03-21'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2019-05-22'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('2019-05-27'); ... Read More

How to get number of rows in a table without using count(*) MySQL query?

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

595 Views

You can use count(1). Let us first see the syntax −select count(1) from yourTableName;Let us first create a table −mysql> create table DemoTable    (    StudentName varchar(100)    ); Query OK, 0 rows affected (0.84 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentName) values('John Smith'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable(StudentName) values('Chris Brown'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(StudentName) values('David Miller'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(StudentName) values('Carol Taylor'); Query OK, 1 row affected (0.15 sec)Display all records from ... Read More

How to find string count of a particular id in a column using a MySQL query?

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

115 Views

For this, use the CHAR_LENGTH() function in MySQL. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Subject longtext    ); Query OK, 0 rows affected (1.17 sec)Now you can insert some records in the table using insert command −mysql> insert into DemoTable(Subject) values('MySQL, MongoDB'); Query OK,  1 row affected (0.20 sec) mysql> insert into DemoTable(Subject) values('MySQL, MongoDB'); Query OK,  1 row affected (0.17 sec) mysql> insert into DemoTable(Subject) values('MongoDB'); Query OK,  1 row affected (0.13 sec) mysql> insert into DemoTable(Subject) values('MySQL'); Query OK,  1 row affected (0.15 sec) Display all records from the table using select statement : mysql> select *from DemoTable;Output+----+---------------+ | Id | Subject | +----+---------------+ | 1 | MySQL, MongoDB | | 2 | MySQL, MongoDB | | ... Read More

How do I avoid the variable value in a MySQL stored procedure to change when records are updated?

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

144 Views

We will create a stored procedure that does not change the variable value whenever the value is updated.Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Value int    ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value) values(100); Query OK, 1 row affected (0.13 sec) Display all records from the table using select statement : mysql> select *from DemoTable;Output+----+-------+ | Id | Value | +----+-------+ | 1 | 100 | +----+-------+ 1 row ... Read More

How to perform SELECT using COUNT in MySQL?

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

109 Views

To perform SELECT with COUNT, use aggregate function COUNT(). Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(100),    Subject varchar(100)    ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name, Subject) values('John', 'MySQL'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(Name, Subject) values('John', 'Java'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(Name, Subject) values('Carol', 'MongoDB'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(Name, Subject) values('Carol', ... Read More

Changing data type from date to date/time in MySQL?

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

513 Views

To change data type from date to date/time, use alter command.alter table yourTableName change yourColumnName yourColumnName datetime;Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    LoginDate date    ); Query OK, 0 rows affected (1.26 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(LoginDate) values('2019-01-21'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable(LoginDate) values('2018-05-01'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(LoginDate) values('2017-12-31'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement ... Read More

MySQL Select displaying Data type in a separate column?

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

67 Views

You can use INFORMATION_SCHEMA.COLUMNS 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 (0.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('Chris'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable(Name) values('Robert'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable(Name) values('Sam'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following ... Read More

How can fetch records from specific month and year in a MySQL table?

Smita Kapse
Updated on 30-Jul-2019 22:30:26

561 Views

Use YEAR() and MONTH() to display records from specific month and year respectively. Let us first create a table −mysql> create table DemoTable    (    CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    CustomerName varchar(20),    CustomerTotalBill int,    PurchasingDate date    ); Query OK, 0 rows affected (0.83 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(CustomerName, CustomerTotalBill, PurchasingDate) values('John', 2000, '2019-01-21'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(CustomerName, CustomerTotalBill, PurchasingDate) values('Chris', 1000, '2019-01-31'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(CustomerName, CustomerTotalBill, PurchasingDate) values('Robert', ... Read More

How to make MySQL table primary key auto increment?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

1K+ Views

To make MySQL table primary key auto increment, use the below syntaxCREATE TABLE yourTableName    (    yourColumnName INT(6) ZEROFILL NOT NULL AUTO_INCREMENT,    PRIMARY KEY(yourColumnName)    );Let us first create a table and set primary key auto increment −mysql> CREATE TABLE DemoTable    (    UserId INT(6) ZEROFILL NOT NULL AUTO_INCREMENT,    PRIMARY KEY(UserId)    ); Query OK, 0 rows affected (0.81 sec)Insert some records in the table using insert command −mysql> INSERT INTO DemoTable values(); Query OK, 1 row affected (0.12 sec) mysql> INSERT INTO DemoTable values(); Query OK, 1 row affected (0.13 sec) mysql> INSERT ... Read More

How to search by specific pattern in MySQL?

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

115 Views

You can use regular expression for this. Let us first create a table −mysql> create table DemoTable    (    UserId varchar(100)    ); Query OK, 0 rows affected (1.28 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('User-123-G'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Us-453-GO'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('TRUE-908-K'); Query OK, 1 row affected (0.20 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+------------+ | UserId     | ... Read More

Advertisements