Found 4219 Articles for MySQLi

How to multiply columns and then sum the rows with similar records like customer name?

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

115 Views

To understand this, let us create a table with fields like ID, Customer Name, Items, Price. We will first multiply the items with price. After that the rows with similar records i.e. same customer name will get added.Let us first create a table:mysql> create table DemoTable (    CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    CustomerName varchar(100),    CustomerItems int,    CustomerPrice int ); Query OK, 0 rows affected (0.54 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable(CustomerName, CustomerItems, CustomerPrice)values('Larry', 3, 450); Query OK, 1 row affected (0.24 sec) mysql> ... Read More

Change tinyint default value to 1 in MySQL?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

1K+ Views

You can use DEFAULT command for this. Following is the syntax −alter table yourTableName change yourColumnName yourColumnName TINYINT(1) DEFAULT 1 NOT NULL;Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    UserName varchar(20),    UserAge int,    isMarried tinyint(1) ); Query OK, 0 rows affected (0.80 sec)Let us check the description of table −mysql> desc DemoTable;This will produce the following output −+-----------+-------------+------+-----+---------+----------------+ | Field     | Type        | Null | Key | Default | Extra          | +-----------+-------------+------+-----+---------+----------------+ | Id       ... Read More

Can we use backticks with column value in MySQL?

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

173 Views

You cannot use backticks with column value. For this, use only table name or column name. If you use backtick with column value then MySQL will give the following error message:ERROR 1054 (42S22): Unknown column '191.23.41.10' in 'where clause'Let us first create a table:mysql> create table DemoTable6 (    SystemIPAddress varchar(200) ); Query OK, 0 rows affected (0.46 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable values('192.68.1.0'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('191.23.41.10'); Query OK, 1 row affected (0.12 sec)Now you can display specific record ... Read More

Delete last 4 letters in MySQL?

Samual Sam
Updated on 30-Jul-2019 22:30:25

73 Views

You can use SUBSTRING() along with UPDATE command to delete last 4 letters. Let us first create a table −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentSubject varchar(100) ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentSubject) values('Introduction to Java'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(StudentSubject) values('Introduction to C'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentSubject) values('Introduction to C++'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(StudentSubject) values('Spring And Hibernate'); ... Read More

Do Double Equal Sign exist in MySQL?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

2K+ Views

There is no double equal sign concept. It can be used to compare two values. If you use double equal sign(==) in MySQL, you will get an error message.Let us verify the concept is true or not. Declare a variable −mysql> set @Number=10; Query OK, 0 rows affected (0.00 sec)Now, compare the above variable value with 10. If both the values are same then the result will be 1 otherwise 0.Using double equal sign −mysql> select 10==@Number;This will produce the following output i.e. an error −ERROR 1064 (42000): You have an error in your SQL syntax; check the manual ... Read More

Can I use SUM() with IF() in MySQL?

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

186 Views

Yes, you can use SUM() with IF() in MySQL. Let us first create a demo table:mysql> create table DemoTable (    Value int,    Value2 int ); Query OK, 0 rows affected (0.51 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable values(100, 400); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(100, 400); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(400, 100); Query OK, 1 row affected (0.14 sec)Following is the query to display records from the table using select command:mysql> select *from DemoTable;This ... Read More

MySQL query to get sum of each column where every column has same number of values?

Samual Sam
Updated on 30-Jul-2019 22:30:25

334 Views

You can use aggregate function SUM() for this. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstValue int,    SecondValue int,    ThirdValue int    ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstValue, SecondValue, ThirdValue) values(10, 20, 30); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable(FirstValue, SecondValue, ThirdValue) values(60, 50, 40); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(FirstValue, SecondValue, ThirdValue) values(80, 90, 100); Query OK, 1 row affected ... Read More

Get the count of only unique rows in a MySQL column?

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

138 Views

In MySQL, COUNT() will display the number of rows. DISTINCT is used to ignore duplicate rows and get the count of only unique rows.Let us first create a table:mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstName varchar(10) ); Query OK, 0 rows affected (0.47 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable(FirstName) values('Larry'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(FirstName) values('John'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(FirstName) values('Sam'); Query OK, 1 row affected (0.13 sec) ... Read More

How do you select from MySQL where last value in a string = x?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

165 Views

You can use LIKE operator with wildcards to select the records where last value in a string = x, for example ‘10’, ‘15’, etc.Let us first create a table −mysql> create table DemoTable (    ClientId varchar(20) ); Query OK, 0 rows affected (0.68 sec)Insert records in the table using insert command −mysql> insert into DemoTable values('CLI-101'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('CLI-110'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('CLI-201'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('CLI-210'); Query OK, 1 row affected (0.13 sec) ... Read More

How to alter the data type of a MySQL table’s column?

Samual Sam
Updated on 30-Jul-2019 22:30:25

124 Views

You can use modify command for this. Let us first us create a table.mysql> create table DemoTable (    StudentId varchar(200) not null,    StudentName varchar(20),    StudentAge int,    StudentAddress varchar(20),    StudentCountryName varchar(20) ); Query OK, 0 rows affected (0.73 sec)Now check the description of table.mysql> desc DemoTable;This will produce the following output −+--------------------+--------------+------+-----+---------+-------+ | Field              | Type         | Null | Key | Default | Extra | +--------------------+--------------+------+-----+---------+-------+ | StudentId          | varchar(200) | NO   |     | NULL    |     ... Read More

Advertisements