Found 4219 Articles for MySQLi

MySQL query to get the count of rows in which two or more specified values appear?

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

58 Views

To get the count of rows in which two or more specified values appear, let us first create a sample table:mysql> create table specifiedValuesDemo -> ( -> Value int, -> Value2 int, -> Value3 int -> ); Query OK, 0 rows affected (0.60 sec)Following is the query to insert some records in the table using insert command:mysql> insert into specifiedValuesDemo values(10, 15, 20); Query OK, 1 row affected (0.17 sec) mysql> insert into specifiedValuesDemo values(40, 10, 20); Query OK, 1 row affected (0.16 sec) ... Read More

Write a MySQL query equivalent to “SHOW TABLES” in sorted order?

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

81 Views

Use INFORMATION_SCHEMA.TABLES to display tables in sorted order. The below syntax will give sorted list of tables in ascending order:select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA= 'yourDatabaseName' order by TABLE_NAME;Following is the query to implement the equivalent to SHOW TABLES:mysql> select TABLE_NAME from INFORMATION_SCHEMA.TABLES    -> where TABLE_SCHEMA= 'sample' order by TABLE_NAME;This will produce the following output+------------------------------------+ | TABLE_NAME                         | +------------------------------------+ | a                                  | | accumulateddemo               ... Read More

How to suppress MySQL stored procedure output?

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

846 Views

To suppress MySQL stored procedure output, you can use variable. Let us first create a table.mysql> create table person_information    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.50 sec)Following is the query to insert some records in the table using insert command:mysql> insert into person_information values(100, 'John'); Query OK, 1 row affected (0.17 sec) mysql> insert into person_information values(101, 'Chris'); Query OK, 1 row affected (0.22 sec) mysql> insert into person_information values(102, 'Robert'); Query OK, 1 row affected (0.16 sec)Following is the query to display records from ... Read More

How to add column using alter in MySQL?

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

141 Views

Following is the syntax to add column using alter in MySQL:alter table yourTableName add column yourColumnName yourDataType default yourValue;Let us first create a table:mysql> create table alterTableDemo    -> (    -> Id int,    -> Name varchar(10)    -> ); Query OK, 0 rows affected (0.69 sec)Let us check the description of the table using DESC command. This displays Field, Type, Key, etc. of the table:mysql> desc alterTableDemo;This will produce the following output+-------+-------------+------+-----+---------+-------+ | Field | Type        | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | Id    | int(11)     | YES ... Read More

Can we order a MySQL result with mathematical operations?

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

201 Views

Yes, we can order with mathematical operations using ORDER BY clause. Let us first create a table:mysql> create table orderByMathCalculation    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Quantity int,    -> Price int    -> ); Query OK, 0 rows affected (0.57 sec)Following is the query to insert some records in the table using insert command:mysql> insert into orderByMathCalculation(Quantity, Price) values(10, 50); Query OK, 1 row affected (0.21 sec) mysql> insert into orderByMathCalculation(Quantity, Price) values(20, 40); Query OK, 1 row affected (0.14 sec) mysql> insert into orderByMathCalculation(Quantity, Price) values(2, 20); Query ... Read More

Difference between count(*) and count(columnName) in MySQL?

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

2K+ Views

The count(*) returns all rows whether column contains null value or not while count(columnName) returns the number of rows except null rows.Let us first create a table.Following is the querymysql> create table ifNotNullDemo    -> (    -> Name varchar(20)    -> ); 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 ifNotNullDemo values('Chris'); Query OK, 1 row affected (0.15 sec) mysql> insert into ifNotNullDemo values(''); Query OK, 1 row affected (0.13 sec) mysql> insert into ifNotNullDemo values('Robert'); Query OK, 1 row affected (0.24 sec) ... Read More

Resolve Unknown database in JDBC error with Java-MySQL?

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

8K+ Views

This type of error occurs if you select any database that does not exist in MySQL. Let us first display the error of unknown database in JDBC.The Java code is as follows. Here, we have set the database as ‘onlinebookstore’, which does not exist:import java.sql.Connection; import java.sql.DriverManager; public class UnknownDatabaseDemo {    public static void main(String[] args) {       String JdbcURL = "jdbc:mysql://localhost:3306/onlinebookstore?useSSL=false";       String Username = "root";       String password = "123456";       Connection con = null;       try {          con = DriverManager.getConnection(JdbcURL, Username, password); ... Read More

How do I INSERT INTO from one MySQL table into another table and set the value of one column?

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

284 Views

Let us first create a table. Following is the query −mysql> create table insertOneToAnotherTable    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.60 sec)Following is the query to insert some records in the table using insert command −mysql> insert into insertOneToAnotherTable values(100); Query OK, 1 row affected (0.08 sec) mysql> insert into insertOneToAnotherTable values(200); Query OK, 1 row affected (0.15 sec) mysql> insert into insertOneToAnotherTable values(300); Query OK, 1 row affected (0.13 sec) mysql> insert into insertOneToAnotherTable values(400); Query OK, 1 row affected (0.15 sec) mysql> insert into insertOneToAnotherTable ... Read More

Select results from the middle of a sorted list in MySQL?

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

815 Views

To select results from the middle of a sorted list, use ORDER BY clause along with LIMIT.Let us first create a table. Following is the query −mysql> create table sortedListDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(100)    -> ); 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 sortedListDemo(StudentName) values('John'); Query OK, 1 row affected (0.62 sec) mysql> insert into sortedListDemo(StudentName) values('Sam'); Query OK, 1 row affected (0.18 sec) mysql> insert into sortedListDemo(StudentName) values('Adam'); ... Read More

Reorder integer except for value 0 with MySQL?

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

55 Views

To reorder integer except for value 0, use the below syntax −select *from yourTableName order by yourColumnName=0 ,yourColumnName;Let us first create a table −mysql> create table reorderIntegerExcept0    -> (    -> value int    -> ); Query OK, 0 rows affected (0.70 sec)Following is the query to insert records in the table using insert command −mysql> insert into reorderIntegerExcept0 values(90); Query OK, 1 row affected (0.17 sec) mysql> insert into reorderIntegerExcept0 values(10); Query OK, 1 row affected (0.21 sec) mysql> insert into reorderIntegerExcept0 values(0); Query OK, 1 row affected (0.18 sec) mysql> insert into reorderIntegerExcept0 values(40); ... Read More

Advertisements