MySQL Articles

Page 114 of 355

How MySQL stored GENERATED COLUMNS can work with mathematical expressions?

Samual Sam
Samual Sam
Updated on 21-Feb-2020 201 Views

It can be illustrated with the help of an example in which we are creating a stored generated column in the table named ‘triangle_stored’. As we know that stored generated column can be generated by using the keyword ‘stored’.Examplemysql> Create table triangle_stored(SideA DOUBLE, SideB DOUBLE, SideC DOUBLE AS (SQRT(SideA * SideB + SideB * SideB)) STORED); Query OK, 0 rows affected (0.47 sec) mysql> Describe triangle_stored; +-------+--------+------+-----+---------+------------------+ | Field | Type | Null | Key | Default | Extra | +-------+--------+------+-----+---------+------------------+ | SideA | double | ...

Read More

How Can MySQL virtual GENERATED COLUMNS work with built-in functions?

Ayyan
Ayyan
Updated on 21-Feb-2020 349 Views

It can be illustrated with the help of an example in which we are creating a virtual generated column in the table named ‘employee_data’. As we know that virtual generated column can be generated with or without using the keyword ‘virtual’.Examplemysql> Create table employee_data(ID INT AUTO_INCREMENT PRIMARY KEY, First_name VARCHAR(50) NOT NULL, Last_name VARCHAR(50) NOT NULL, FULL_NAME VARCHAR(90) GENERATED ALWAYS AS(CONCAT(First_name, '', Last_name))); Query OK, 0 rows affected (0.55 sec) mysql> DESCRIBE employee_data; +------------+-------------+------+-----+---------+-------------------+ | Field | Type ...

Read More

How can we compare data in two MySQL tables?

Prabhas
Prabhas
Updated on 14-Feb-2020 2K+ Views

Sometimes we need to identify the unmatched data from two tables, especially in the case when data is migrated. It can be done by comparing the tables. Consider the example below in which we have two tables named ‘students’ and ‘student1’.mysql> Select * from students; +--------+--------+----------+ | RollNo | Name   | Subject  | +--------+--------+----------+ |    100 | Gaurav | Computer | |    101 | Raman  | History  | |    102 | Somil  | Computer | +--------+--------+----------+ 3 rows in set (0.00 sec) mysql> select * from student1; +--------+--------+----------+ | RollNo | Name | Subject | ...

Read More

Can we use MySQL GROUP BY clause with multiple columns like MySQL DISTINCT clause is used?

varma
varma
Updated on 14-Feb-2020 10K+ Views

Yes, it is possible to use MySQL GROUP BY clause with multiple columns just as we can use MySQL DISTINCT clause. Consider the following example in which we have used DISTINCT clause in first query and GROUP BY clause in the second query, on ‘fname’ and ‘Lname’ columns of the table named ‘testing’.mysql> Select * from testing; +------+---------+---------+ | id   | fname   | Lname   | +------+---------+---------+ |  200 | Raman   | Kumar   | |  201 | Sahil   | Bhalla  | |  202 | Gaurav  | NULL    | |  203 | Aarav   | ...

Read More

Why it shows 0 instead of empty string whenever I insert an empty string into a MySQL column which is declared as NOT NULL?

Rishi Rathor
Rishi Rathor
Updated on 14-Feb-2020 1K+ Views

It is because inserting an empty string means that we are inserting some value and not NULL. The empty string apparently maps to zero as an integer. In other words, we can say that by inserting empty string we are providing a value to MySQL that has integer representation as INT 0. Consider the following example in which we inserted an empty string and it mapped to 0 by MySQL.mysql> create table test(id int NOT NULL, Name Varchar(10)); Query OK, 0 rows affected (0.19 sec) mysql> Insert into test(id, name) values('1', 'Gaurav'), ('0', 'Rahul'), ('', 'Aarav'); Query OK, 3 ...

Read More

How can we find out the current transaction mode in MySQL?

Monica Mona
Monica Mona
Updated on 14-Feb-2020 685 Views

We can run “SELECT @@AUTOCOMMIT” command to check the current transaction mode.mysql> Select @@AUTOCOMMIT; +--------------------+ | @@AUTOCOMMIT | +--------------------+ | 1 | +--------------------+ 1 row in set (0.05 sec) mysql> SET AUTOCOMMIT = 0; Query OK, 0 rows affected (0.00 sec) mysql> Select @@AUTOCOMMIT; +--------------------+ | @@AUTOCOMMIT | +--------------------+ | 0 | +--------------------+ 1 row in set (0.00 sec)

Read More

What happens if MySQL query returns no rows?

varun
varun
Updated on 13-Feb-2020 2K+ Views

From the output returned by MySQL, it is very much clear that how many rows are there in the result set along with the execution time.ExampleFor example, in the following MySQL output we can see there are 3 rows in the result set.mysql> Select * from ratelist ORDER BY Price LIMIT 3; +----+------+-------+ | Sr | Item | Price | +----+------+-------+ |  5 | T    |   250 | |  1 | A    |   502 | |  2 | B    |   630 | +----+------+-------+ 3 rows in set (0.00 sec)But suppose if MySQL query has ...

Read More

While connecting to one MySQL database, how can I see the list of tables of other MySQL database?

seetha
seetha
Updated on 13-Feb-2020 225 Views

With the help of SHOW TABLES From Database_name query, we can see the tables of another database. Here Database_name is the name of the database which we are not using currently. Consider the following example in which we run the query for getting the list of tables in database name ‘tutorial’.mysql> show tables from tutorial; +--------------------+ | Tables_in_tutorial | +--------------------+ | employee           | | showzerofill       | | student            | +--------------------+ 3 rows in set (0.00 sec)

Read More

How do we count the total duplicate records in a column of MySQL table?

Abhinaya
Abhinaya
Updated on 13-Feb-2020 2K+ Views

Suppose we have the following table named stock_item in which the column quantity is having duplicate values i.e. for item name ‘Notebooks’ and ‘Pencil’, the column ‘Quantity’ is having duplicate values ‘40’ and for items ‘Shirts’, ‘Shoes’ and ‘Trousers’ triplicate value 29 is hold by column ‘quantity’ as shown in the table.mysql> Select * from stock_item; +------------+----------+ | item_name  |quantity  | +------------+----------+ | Calculator |       89 | | Notebooks  |       40 | | Pencil     |       40 | | Pens       |       32 | | ...

Read More

How MySQL stored function evaluates if it got NULL value while using the dynamic values from a table?

Ramu Prasad
Ramu Prasad
Updated on 13-Feb-2020 288 Views

In such kind of cases when a stored function got NULL values then it will return NULL as the result. It can be understood from the example below in which we have a NULL value in the records of student ‘Mohit’. Now, when we will apply the stored function ‘avg_marks’ on this data, it will return NULL as result.mysql> Select * from Student_marks; +-------+------+---------+---------+---------+ | Name  | Math | English | Science | History | +-------+------+---------+---------+---------+ | Raman |   95 |      89 |      85 |      81 | | Rahul |   90 | ...

Read More
Showing 1131–1140 of 3,547 articles
« Prev 1 112 113 114 115 116 355 Next »
Advertisements