Found 4219 Articles for MySQLi

In MySQL, how we can write Multiple-line statement?

Nitya Raut
Updated on 22-Jun-2020 08:46:50

4K+ Views

We can write multiple-line statements because MySQL determines the end of a statement by looking for the termination semicolon, not by looking for the end of the input line.Examplemysql> Select *     -> from     -> stock_item; +------------+-------+----------+ | item_name  | Value | Quantity | +------------+-------+----------+ | Calculator | 15    | 89      | | Notebooks  | 63    | 40      | | Pencil     | 15    | 40      | | Pens       | 65    | 32      | | Shirts     | 13   ... Read More

How can create a table having the name like a^b along with same column name?name?

Priya Pallavi
Updated on 22-Jun-2020 08:46:26

64 Views

For creating a table with such kinds of names we must have to use quote character. The quotes can be single or double depends upon ANSI_QUOTES SQL mode. If this mode is disabled then the identifier quote character is the backtick (“`”). Consider the following example in which we created a table named ‘select’ −mysql> Create table `a^b`(`a^b` int); Query OK, 0 rows affected (0.19 sec) mysql> Create table "a^g"("a^g" int); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"a^g" ("a^g" ... Read More

How is it possible to enter multiple MySQL statements on a single line?

usharani
Updated on 22-Jun-2020 08:30:51

1K+ Views

As we know that a query consists of MySQL statements followed by a semicolon. We can enter multiple MySQL statements, separated by semicolons, on a single line. Consider the following example −mysql> Select * from Student; Select * from Student ORDER BY Name; +--------+--------+--------+ | Name   | RollNo | Grade  | +--------+--------+--------+ | Gaurav | 100    | B.tech | | Aarav  | 150    | M.SC   | | Aryan  | 165    | M.tech | +--------+--------+--------+ 3 rows in set (0.00 sec) +--------+--------+--------+ | Name   | RollNo | Grade  | +--------+--------+--------+ | Aarav  | 150 ... Read More

How can I query for all the tables having a particular column name?

Jennifer Nicholas
Updated on 22-Jun-2020 08:31:31

106 Views

For writing MySQL query to get all the tables having a particular column name, we can use LIKE operator. It can be understood with the help of an example as follows −ExampleFollowing is the MySQL query to get all the tables having columns name ‘ID’ in it −mysql> Select Column_name as 'ColumnName', Table_name As 'Tablename' FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE '%ID%' ORDER BY Tablename LIMIT 10; +-------------+---------------+ | ColumnName  | Tablename     | +-------------+---------------+ | id          | arena         | | id          | arena1        | ... Read More

How can we amend the declared size of a column’s data type in MySQL?

Vrundesha Joshi
Updated on 22-Jun-2020 08:33:02

66 Views

It can be done with the help of ALTER TABLE command of MySQL. Consider the table ‘Student’ in which the size of ‘Grade’ column is declared as Varchar(10), can be seen from the following query −mysql> DESCRIBE Student; +--------+-------------+------+-----+---------+-------+ | Field  | Type        | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | Name   | varchar(20) | YES  |     | NULL    |       | | RollNo | int(11)     | YES  |     | NULL    |       | | Grade  | varchar(10) | YES  | ... Read More

How can we sort multiple columns in a single query?

seetha
Updated on 22-Jun-2020 08:36:05

113 Views

We can sort multiple columns in a single query by giving more than one column name with ORDER BY Clause. The syntax of the above is as follows −SyntaxSelect Col1, Col2, … from table_name ORDER BY Col1, Col2, …ExampleSuppose we want to sort the table named ‘Student’ by columns ‘Name’ and ‘RollNo’ both then we can write the single query for this as follows −mysql> Select Name, RollNo from student order by name, rollno; +--------+--------+ | name   | rollno | +--------+--------+ | Aarav  |    150 | | Aryan  |    165 | | Gaurav |    100 | ... Read More

How can I get the information about a particular column of a table by MySQL EXPLAIN statement?EXPLAIN statement?

Prabhas
Updated on 22-Jun-2020 08:33:44

74 Views

As we know the EXPLAIN statement will provide the information/structure of the whole table. With the help of the EXPLAIN statement along with the table name and the column name, we can get the information about that column.SyntaxEXPLAIN table_name col_name;Example1mysql> EXPLAIN employee ID; +-------+---------+------+-----+---------+----------------+ | Field | Type    | Null | Key | Default | Extra          | +-------+---------+------+-----+---------+----------------+ | ID    | int(11) | NO   | PRI | NULL    | auto_increment | +-------+---------+------+-----+---------+----------------+ 1 row in set (0.11 sec)The query above will give the information about the column ‘ID’ of a table named ... Read More

How we can get more information about columns of a table than theinformation we got by DESCRIBE, EXPLAIN and SHOW COLUMNS MySQL statements?

Vrundesha Joshi
Updated on 22-Jun-2020 08:34:54

71 Views

With the statement SHOW FULL COLUMNS, we can get more information about the columns of a table than the information we got by DESCRIBE, EXPLAIN, and SHOW COLUMNS MySQL statements.SyntaxSHOW FULL COLUMNS from Table_name;Examplemysql> SHOW FULL COLUMNS FROM EMPLOYEE\G; *************************** 1. row ***************************      Field: ID       Type: int(11)  Collation: NULL       Null: NO        Key: PRI    Default: NULL      Extra: auto_increment Privileges: select, insert, update, references    Comment: *************************** 2. row ***************************      Field: Name       Type: varchar(20)  Collation: latin1_swedish_ci       Null: YES ... Read More

What are the synonym statements of MySQL DESCRIBE?

vanithasree
Updated on 22-Jun-2020 08:37:27

188 Views

Followings are the synonyms statements of MySQL DESCRIBE i.e. the statements with the help of which we can get the same kind of information/structure of the table as we get from DESCRIBE −EXPLAIN StatementEXPLAIN is the synonym of the DESCRIBE statement. Its syntax is also similar to the DESCRIBE statement. Consider the following example −mysql> Explain Employee; +-------+-------------+------+-----+---------+------------------+ | Field | Type        | Null | Key | Default | Extra            | +-------+-------------+------+-----+---------+------------------+ | ID    | int(11)     | NO   | PRI | NULL    | auto_increment   | | ... Read More

How can we use a MySQL subquery with FROM clause?

Arushi
Updated on 22-Jun-2020 08:38:19

198 Views

Subqueries can work well in a SELECT statement FROM clause. Following is the syntax for the same −SELECT … FROM(subquery) [AS] name …To make it understand we are using the following data from table ‘cars’ −mysql> Select * from Cars; +------+--------------+---------+ | ID   | Name         | Price   | +------+--------------+---------+ | 1    | Nexa         | 750000  | | 2    | Maruti Swift | 450000  | | 3    | BMW          | 4450000 | | 4    | VOLVO        | 2250000 | | ... Read More

Advertisements