Trending February 2024 # A Quick Glance Of Mysql Having With Examples # Suggested March 2024 # Top 2 Popular

You are reading the article A Quick Glance Of Mysql Having With Examples updated in February 2024 on the website We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested March 2024 A Quick Glance Of Mysql Having With Examples

Introduction to MySQL having

In real-time applications, we often need to generate complex reports from the data saved in the database and retrieve the filtered records to display the report to the user. For this, your SQL query must be optimized and correct so that the application’s performance is not hampered even if a large amount of data is present in the tables. The SELECT query constructed for such reports needs to use the functionalities provided in MySQL.

Start Your Free Data Science Course

Having a clause is one such functionality that helps apply the expressions’ filters. These expressions can consist of a single column, multiple columns, or even conditions applied to the grouped aggregated data retrieved using the GROUP BY clause. In this article, we will learn about the syntax of the HAVING clause, its evaluation order while execution, and study some examples to get a grip on the usage of the HAVING clause in your queries for retrieval of data.


The following SELECT query shows the syntax and placement of the HAVING clause in it –

SELECT list_of_expressions FROM name_of_table WHERE restrictions_and_conditions GROUP BY expressions_for_grouping HAVING condition_or_filter_on_grouped_expressions;

In the above syntax –

list_of_expressions – The comma-separated list of the columns and the other expressions, such as aggregated values or manipulated values such as product, etc., that the query needs to retrieve from the table data.

name_of_table – The table’s name resides in your database and from where the summarized data needs to be retrieved for your use case.

restrictions_and_conditions – These are the conditions you can specify on the table columns that need to be fulfilled while retrieving the data.

expressions_for_grouping – The resultset retrieved from the query structure above the GROUP BY clause can be summarized and grouped based on certain expressions, including columns and aggregated values of columns as the expressions_for_grouping.

condition_or_filter_on_grouped_expressions – The WHERE clause only applies restrictions on the individual records or row of the column. We can use the HAVING clause to apply filters and restrictions and specify conditions on the grouped expressions of the resultset.

In the case of the HAVING clause, the restriction is applied to the grouped values retrieved instead of a single row of the table. When we do not use the GROUP BY clause in the SELECT query, the HAVING clause behaves in the same manner as that of the WHERE clause and applies restriction on individual row-level of the table as grouping expression is absent. If the filter condition specified in the HAVING clause evaluates to true, the grouped record is included in the final resultset based on the GROUP BY clause. Conversely, if the condition evaluates to false, the record is excluded.

Evaluation order:

The evaluation order followed by standard SQL is different than that of MySQL. Evaluation order determines which and when clause will be considered for execution when the SELECT query contains multiple clauses. The diagram below illustrates the order in which MySQL evaluates the clauses of the SELECT query.

Here, we observe that the evaluation of the HAVING clause takes place after the FROM, WHERE, SELECT, and GROUP BY clauses, but before the LIMIT and ORDER BY clauses. However, it is important to note that in the SQL standard, the evaluation order differs. In this case, the execution of the HAVING clause occurs after the GROUP BY clause and before the SELECT clause.

Example of MySQL having CREATE TABLE educba_articles ( id INTEGER AUTO_INCREMENT PRIMARY KEY, articlename varchar(10) NOT NULL, author varchar(10) NOT NULL, rate decimal(5,2) DEFAULT NULL, month varchar(10) NOT NULL, status varchar(10) NOT NULL, pages INTEGER DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_danish_ci;

that gives the following output after execution –

Now, we will insert some records in it –

INSERT INTO `educba_articles` VALUES (1, 'sp', 'Payal', 125.65, 'May','Submitted' ,3), (2,'having', 'Vyankatesh', 326.22, 'June','Pending' ,2), (3,'something', 'Omprakash', 123.22, 'July','Approved' ,2), (4, 'anything','sakshi', 645.54 ,'May','Pending' ,3), (5, 'everything','prerna', 356.54 ,'June','Submitted' ,4), (6,'events', 'Vyankatesh', 326.22, 'June','Approved' ,2), (7,'group by', 'Omprakash', 123.22, 'July','Approved' ,2), (8, 'from','sakshi', 645.54, 'May','Pending' ,3), (9, 'where','prerna', 356.54 ,'June','Submitted' ,4), (10, 'limit ', 'Payal', 125.65, 'May','Submitted' ,3), (11, 'coalesce ', 'Payal', 125.65, 'May','Submitted' ,3), (12,'order by', 'Vyankatesh', 326.22, 'June','Approved' ,2), (13,'datatypes', 'Omprakash', 123.22, 'July','Approved' ,2), (14, 'varchar','sakshi', 645.54 ,'May','Pending' ,3), (15, 'integer','prerna', 356.54 ,'June','Approved' ,4), (16,'date', 'Vyankatesh', 326.22, 'June','Pending' ,2), (17,'now', 'Omprakash', 123.22, 'July','Approved' ,2), (18, 'curdate','sakshi', 645.54 ,'May','Pending' ,3), (19, 'not null','prerna', 356.54, 'June','Pending' ,4);

that provides the following result after execution –

SELECT author, MONTH, SUM(rate*pages) AS payment FROM educba_articles GROUP BY author, MONTH

that gives the following output –

Let’s consider another example where our goal is to retrieve the total payment that we need to pay to each author. In this case, the total payment for all months should exceed 5000. To achieve this, we need to group the data by author, calculate the payment by multiplying the rate and pages, and aggregate this value using the SUM() function to calculate the total payment for each author. Additionally, we should apply a restriction on the calculated value within the HAVING clause. Our query statement will look like follows –

SELECT author, SUM(rate*pages) AS payment FROM educba_articles GROUP BY author;

that gives the following output after execution –


HAVING clause can be used to apply restrictions and filters on the grouped expressions in complex queries that are generally used for reporting purposes using the SELECT query statement in MySQL.

Recommended Articles

We hope that this EDUCBA information on “MySQL having” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

You're reading A Quick Glance Of Mysql Having With Examples

A Quick Glance Of Matlab Trapz() With Proramming Example

Introduction to Matlab trapz()

MATLAB has incorporated the function trapz to process numerical integration using trapezoidal rule-following unit spacing. This rule is defined to approximate a numerical integration for a definite time frame by dividing the area under the plot into tine sized trapezoids. It helps in forming easily computable areas. The function returns the single return value of type scalar which is the final value of the integration.

Preferably trapz is recommended to use for numerical integration on discrete type data sets.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others


This integrating function trapz accepts different input arguments to decide on the behavior of the integration function, being used with different syntaxes respectively.

They are:

Syntax Description

Q = trapz(Y) This syntax calculates the approximate integral value for ‘Y’ with unit spacing where the dimensions of the integration is determined based on the size of ‘Y’.

Q = trapz(X,Y) This syntax calculates the approximate integral value for ‘Y’ with ‘X’ specified scalar spacing, where the dimensions of the integration is determined based on the size of ‘Y’.

This syntax calculates the approximate integral value for the input with the dimensions of the integration given as ‘dim’.

The input arguments that contribute to different syntaxes of the function trapz can be explained as below:

Numeric Data-Y

The input data over which trapz function is called to operate numerical integration operation.

Depending on the nature of ‘Y’ the integration operation takes place differently such as:

1. Y as vector àThe output is an approximated integral result for ‘Y’

3. Y as multi-dimensional arrayà The operation takes place on the first non-unit sized dimension of ‘Y’ and results in the size of value 1 for that dimension while the size of the other dimensions remains unchanged.

The data type supported by ‘Y’ are:

single/ double/ complex number

Point spacing-X

The specified point spacing value over which the number of trapezoids to be formed is decided.

Value of X of different nature needs to follow come conditions as mentioned below:

1. X as vector à The length of the coordinate vector must be equal to the size of the first non-unit sized dimension of the numerical input ‘Y’.

2. X as scalaràIt satisfies the condition as

trapz(Y, X) = X*trapz(Y)

The default value of ‘X’ is ‘1’.

The data type supported by ‘X’ are single/ double

Dimensions for operation-dim

Decides the direction along which the integration operation will be performed.

2 different dimensions in which trapz works are as follows:

1. trapz(Y,1):

It operates on elements with columns of ‘Y’, returning a row vector as output.

2. trapz(Y,2):

It operates on elements with rows of ‘Y’, returning a column vector as output.

The value is dim must be a positive integer.

Examples of Matlab trapz()

Here are the following examples mention below:

Example #1 – Numerical integration with Unit spacing

This operation can be executed by applying the syntax Q = trapz(Y) in the trapz function implementation in the MATLAB code.


The below code snippet is written to execute trapz operation on input numeric ‘Y’ as f(x)= 10*2^x.

Q = trapz(Y)


Example #2 – Numerical integration with Non-Unit spacing

This operation can be executed by applying the syntax Q = trapz(Y, X) in the trapz function implementation in the MATLAB code.


The below code is written to call trapz function on input numeric data ‘Y’ having point spacing value of pi/10.


Example #3 – Numerical integration with non-uniform spacing

This operation can be executed by applying the syntax Q = trapz(Y, X, dim) in the trapz function implementation in the MATLAB code.


The below code is written to call the trapz function on the input numeric data ‘Y’ with non-uniform point spacing values defined by ‘X’ with the value of ‘dim’ as ‘2’.

The point spacing is obtained by matrix ‘X’ which indicates that the trapezoids are formed non-uniformly.

The rows in input numeric data ‘Y’ is obtained from velocity data taken at 3 different trials.

Q = trapz(X,Y,2)


Trapz is executed on each row of the input numeric ‘Y’ as the value for ‘dim’ is set to 2. The resultant output is a column vector having an integration result for each row.

Example #4 – Multiple numerical integrations

The integration function trapz can also be used to perform double integral i.e integration in the format:

In order to perform trapz function on double integral expression, the function is called in the nested loop as demonstrated in the below example:

I = trapz(q,trapz(p,F,2))


Example #5 – Real-time application of trapz

The trapz in MATLAB plays a vital role in integration calculations applied in real-time applications.


Trapz can be used to compute the average energy exhibited by an electrical machine for which v-i nonlinear relation is designed as:

The instantaneous voltage v(t)= sin(3t).

In the below code snippet the point spacing is defined by ‘time’ which is non-unit uniform spacing with the value of ‘10’.

The instantaneous power is calculated as p = f(i,v) = v*i.

The average energy (enrgy)  is calculated by applying the trapz function.

xlabel(‘in seconds’); ylabel(‘in joules’)


Additional Note

The integration function trapz is similar to cumtrapz and difference lies as it reduces the dimension size to one and returns a single value without returning any intermediate values of integration.

If input numeric data ‘Y’ is multidimensional array by nature, it works across the first non-singleton dimension whereas the size of other dimensions remains unaffected.

It is similar to integral() and differs in the supported input data types. The function trapz works with discrete values whereas integral() works strictly with function (expression) integration operation.

Recommended Articles

This is a guide to Matlab trapz(). Here we discuss the different an introduction to Matlab trapz() with appropriate syntax and examples. You may also have a look at the following articles to learn more –

Mysql Select Statement With Examples

What is SELECT query in MySQL?

SELECT QUERY is used to fetch the data from the MySQL database. Databases store data for later retrieval. The purpose of MySQL Select is to return from the database tables, one or more rows that match a given criteria. Select query can be used in scripting language like PHP, Ruby, or you can execute it via the command prompt.

SQL SELECT statement syntax

It is the most frequently used SQL command and has the following general syntax


SELECT is the SQL keyword that lets the database know that you want to retrieve data.

FROM tableName is mandatory and must contain at least one table, multiple tables must be separated using commas or joined using the JOIN keyword.

WHERE condition is optional, it can be used to specify criteria in the result set returned from the query.

GROUP BY is used to put together records that have the same field values.

HAVING condition is used to specify criteria when working using the GROUP BY keyword.

ORDER BY is used to specify the sort order of the result set.


The Star symbol is used to select all the columns in table. An example of a simple SELECT statement looks like the one shown below.

SELECT * FROM `members`;

The above statement selects all the fields from the members table. The semi-colon is a statement terminate. It’s not mandatory but is considered a good practice to end your statements like that.

Practical examples

You can learn to import the .sql file into MySQL WorkBench

The Examples are performed on the following two tables

Table 1: members table

membership_ number full_names gender date_of_ birth physical_ address postal_ address contct_ number email

1 Janet Jones Female 21-07-1980 First Street Plot No 4 Private Bag 0759 253 542 [email protected]

2 Janet Smith Jones Female 23-06-1980 Melrose 123 NULL NULL

3 Robert Phil Male 12-07-1989 3rd Street 34 NULL 12345

4 Gloria Williams Female 14-02-1984 2nd Street 23 NULL NULL NULL

Table 2: movies table

movie_id title director year_released category_id

1 Pirates of the Caribean 4 Rob Marshall 2011 1

2 Forgetting Sarah Marshal Nicholas Stoller 2008 2

3 X-Men NULL 2008 NULL

4 Code Name Black Edgar Jimz 2010 NULL

5 Daddy’s Little Girls NULL 2007 8

6 Angels and Demons NULL 2007 6

7 Davinci Code NULL 2007 6

9 Honey mooners John Schultz 2005 8

16 67% Guilty NULL 2012 NULL

Getting members listing

Let’s suppose that we want to get a list of all the registered library members from our database, we would use the script shown below to do that.

SELECT * FROM `members`;

Executing the above script in MySQL workbench produces the following results.

membership_ number full_names gender date_of_ birth physical_ address postal_ address contct_ number email

1 Janet Jones Female 21-07-1980 First Street Plot No 4 Private Bag 0759 253 542 [email protected]

2 Janet Smith Jones Female 23-06-1980 Melrose 123 NULL NULL

3 Robert Phil Male 12-07-1989 3rd Street 34 NULL 12345

4 Gloria Williams Female 14-02-1984 2nd Street 23 NULL NULL NULL

Our above query has returned all the rows and columns from the members table.

Let’s say we are only interested in getting only the full_names, gender, physical_address and email fields only. The following script would help us to achieve this.

SELECT `full_names`,`gender`,`physical_address`, `email` FROM `members`;

Executing the above script in MySQL workbench produces the following results.

full_names gender physical_address email

Janet Jones Female First Street Plot No 4 [email protected]

Janet Smith Jones Female Melrose 123

Robert Phil Male 3rd Street 34

Gloria Williams Female 2nd Street 23 NULL

Getting movies listing

Remember in our above discussion that we mention expressions been used in SELECT statements. Let’s say we want to get a list of movie from our database. We want to have the movie title and the name of the movie director in one field. The name of the movie director should be in brackets. We also want to get the year that the movie was released. The following script helps us do that.

SELECT Concat(`title`, ' (', `director`, ')') , `year_released` FROM `movies`;


The Concat () MySQL function is used join the columns values together.

The line “Concat (`title`, ‘ (‘, `director`, ‘)’) gets the title, adds an opening bracket followed by the name of the director then adds the closing bracket.

String portions are separated using commas in the Concat () function.

Executing the above script in MySQL workbench produces the following result set.

Concat(`title`, ‘ (‘, `director`, ‘)’) year_released

Pirates of the Caribean 4 ( Rob Marshall) 2011

Forgetting Sarah Marshal (Nicholas Stoller) 2008

NULL 2008

Code Name Black (Edgar Jimz) 2010

NULL 2007

NULL 2007

NULL 2007

Honey mooners (John Schultz) 2005

NULL 2012

Alias field names

The above example returned the Concatenation code as the field name for our results. Suppose we want to use a more descriptive field name in our result set. We would use the column alias name to achieve that. The following is the basic syntax for the column alias name


“[AS]” is the optional keyword before the alias name that denotes the expression, value or field name will be returned as.

“`alias_name`” is the alias name that we want to return in our result set as the field name.

The above query with a more meaningful column name

SELECT Concat(`title`, ' (', `director`, ')') AS 'Concat', `year_released` FROM `movies`;

We get the following result

Concat year_released

Pirates of the Caribean 4 ( Rob Marshall) 2011

Forgetting Sarah Marshal (Nicholas Stoller) 2008

NULL 2008

Code Name Black (Edgar Jimz) 2010

NULL 2007

NULL 2007

NULL 2007

Honey mooners (John Schultz) 2005

NULL 2012

Getting members listing showing the year of birth

Suppose we want to get a list of all the members showing the membership number, full names and year of birth, we can use the LEFT string function to extract the year of birth from the date of birth field. The script shown below helps us to do that.

SELECT `membership_number`,`full_names`,LEFT(`date_of_birth`,4) AS `year_of_birth` FROM members;


“LEFT(`date_of_birth`,4)” the LEFT string function accepts the date of birth as the parameter and only returns 4 characters from the left.

“AS `year_of_birth`” is the column alias name that will be returned in our results. Note the AS keyword is optional, you can leave it out and the query will still work.

Executing the above query in MySQL workbench against the myflixdb gives us the results shown below.

membership_number full_names year_of_birth

1 Janet Jones 1980

2 Janet Smith Jones 1980

3 Robert Phil 1989

4 Gloria Williams 1984

SQL using MySQL Workbench

We are now going to use MySQL workbench to generate the script that will display all the field names from our categories table.

2. MySQL workbench will automatically create a SQL query and paste in the editor.

3. Query Results will be show

Notice that we didn’t write the SELECT statement ourselves. MySQL workbench generated it for us.

Why use the SELECT SQL command when we have MySQL Workbench?

Now, you might be thinking why learn the SQL SELECT command to query data from the database when you can simply use a tool such as MySQL workbench’s to get the same results without knowledge of the SQL language. Of course that is possible, but learning how to use the SELECT command gives you more flexibility and control over your SQL SELECT statements.

MySQL workbench falls in the category of “Query by Example” QBE tools. It’s intended to help generate SQL statements faster to increase the user productivity.

Learning the SQL SELECT command can enable you to create complex queries that cannot be easily generated using Query by Example utilities such as MySQL workbench.

To improve productivity you can generate the code using MySQL workbench then customize it to meet your requirements. This can only happen if you understand how the SQL statements work!


The SQL SELECT keyword is used to query data from the database and it’s the most commonly used command.

The simplest form has the syntax “SELECT * FROM tableName;”

Expressions can also be used in the select statement . Example “SELECT quantity + price FROM Sales”

The SQL SELECT command can also have other optional parameters such as WHERE, GROUP BY, HAVING, ORDER BY. They will be discussed later.

MySQL workbench can help develop SQL statements, execute them and produce the output result in the same window.

A Quick Glance On Opencv Version

Introduction to OpenCV Version

The OpenCV is the acronym of the open-source computer vision library used for virtual machine vision or eyesight. It is using in the computer or virtual machines for real-time applications. It is an open-source library used for video operating, image processing, and analysis vision applications. The OpenCV version is using to detect the object using image processing, save and display videos, and analyze and control the motion visions. It is the cross-platform library used for real-time vision and machine learning for robotics and the medical field. The OpenCV is an open-source library of images and videos for real-time computer applications. The users need to updated and adding new features to create the application effectively.

Start Your Free Software Development Course

Different OpenCV Versions 1. OpenCV Alpha Version

It was released in 2000.

It is the first version of the open-source library to create more effective images and videos.

The alpha versions are based on color changing, blending, and preserve the part of images using pixels.

The alpha version focuses on blending the two images without any disturbance of the image pixels.

The two images are placed in one place and create one image with setting color contrast.

The videos or images are collaborating and avoid overlapping of the images.

The latest alpha versions are OpenCV – 3.0.0 alpha and OpenCV – 4.0.0 alpha.

2. OpenCV Beta Version

It was released from 2001 to 2005.

The beta version focused on the contrast of the images and the brightness of the images and videos.

The different OpenCV beta versions were released between 2001 and 2005 year.

The OpenCV beta is mainly focused on the contrast of the images or video’s background and color co-ordinations.

 The beta is set the brightness of the images and videos using pixels of the images.

The beta version is to operate and access the pixel values of the images and initialize with the matrix of the videos or images.

The latest beta versions are OpenCV – 3.0.0 beta and OpenCV – 4.0.0 beta.

3. OpenCV – 1.X Version

The OpenCV – 1.0 version released in the 2006.

The OpenCV – 1.0 is released in 2006 and OpenCV -1.1 version released in 2008.

It mainly focused on face detection and computational geometry using image processing.

The OpenCV – 1.0 version was used for motion templates for videos or images, SIFT features, and camera standardization.

It is focused on the Lucas – Kanade method for the movement of the image objects.

The OpenCV – 1.0 version is useful for decision-making trees, boosting methods of machine learning.

4. OpenCV – 2.X Version

The OpenCV-2.0 version released in the 2009.

The OpenCV 2.0 is based on the C++ library from 2009 – 2010.

The OpenCV – 2.3.0, OpenCV – 2.4.9, OpenCV – 2.4.10, OpenCV – 2.4.11, OpenCV – 2.4.12, and OpenCV – 2.4.13 are available for all browsers and operating system.

The OpenCV – 2.x version binding java and python automatically.

It is based on data structure, multidimensional array, linear and non-linear image filtering, and video analyst.

The OpenCV 2 version is used for geometrical image transformation like resize, color, space, etc.

The OpenCV 2 version focus on video motions modifying, background modification, and basic UI functions.

It was started with GPU acceleration for real-time applications in the computers.

 It was started to set the functions easily in machine learning.

It is using for Java API and android manager for images and video operations.

5. OpenCV – 3.X Version

 The OpenCV-3.0 version released in the 2024.

The OpenCV – 3.0.0, OpenCV – 3.1.0, OpenCV – 3.2.0, OpenCV – 3.3.0, OpenCV – 3.4.0, OpenCV – 3.4.12, and OpenCV – 3.4.13 are available for all browsers and operating system.

The OpenCV – 3.0.0 Alpha, OpenCV – 3.0.0 Beta, and OpenCV – 3.0.0 RC1 are available for all browsers and operating system.

It contains all basic functions with core, image processing, video input/output, image filtering, camera calibration, and video analysis.

It is used for machine learning with High-level GUI, video or image stabilization, and deep neural network module.

 3.x version is focused on 3D image object recognition, improve foreground and background segmentation of the images, medical images, and vision method.

It was started with deep RGB image processing and text recognition or detection.

It extends the image processing and object detection features and modules.

It starts super 3D visualization and better image resolutions using image pixels.

6. OpenCV – 4.X Version

The OpenCV-4.0 version released in the 2023.

The OpenCV – 4.0.0, OpenCV – 4.1.0, OpenCV – 4.1.1, OpenCV – 4.1.2, OpenCV – 4.2.0, OpenCV – 4.3.0, OpenCV – 4.4.0 and OpenCV – 4.5.0 are available for all browsers and operating system.

The OpenCV – 4.0.0 Alpha, OpenCV – 4.0.0 Beta, and OpenCV – 4.0.0 RC1 are available for all browsers and operating systems.

The OpenCV 4.x is based on C++ 11 library and the OpenCV – 1.x version has been removed.

The OpenCV 4.x is the store and load the data from XML and JSON files.

The OpenCV 4.x is added to the graph-based image processing pipeline (G-API).

The OpenCV 4.x is focused on QR code detecting and decoding using the “objdetect” module.

The OpenCV 4.x is supporting to the features of deep learning.

Conclusion Recommended Articles

This is a guide to OpenCV Version. Here we discuss the introduction and different OpenCV versions for better understanding. You may also have a look at the following articles to learn more –

Working Of Transactions With Examples

Introduction to MongoDB Transactions

MongoDB transactions are provided in version 4.0 of Mongo DB where the transactions are supported even in Multi-document operations to maintain the ACID properties. The transactions are supported even across the sharded clusters and the replications of the documents in the Mongo database. There arise many situations where we need a transaction to maintain the atomicity in the operations where the process consists of multi-collection data or multi-document data which is supported by MongoDB transactions.

Start Your Free Data Science Course

In this article, we will have a look at the necessity of the transactions in MongoDB, the ACID properties of the transactions, and have a look at sample examples to demonstrate the use of Mongo DB transactions in your application.

MongoDB Transactions

There are multiple read and write operations being done from and to the Mongo DB database that needs a behavior where all those set of operations should be completed entirely or none of them should be reflected in the database. This integrity of a set of read and write operations is maintained by using transactions.

ACID properties of transactions

All the transactions in Mongo DB follow the properties of ACID which stand for Atomicity, Consistency, Isolation, and durability. It is important for exhibiting all these four characteristics inside your transaction for validation. Let us discuss one by one what all these four properties of ACID stand for –

Atomicity – By this property, we mean that all the operations that are present inside the transaction will together be treated as a single unit which means that the failure of even a single operation will lead to a rollback of all the previously executed operations of that transaction and marking the failure of the transaction. Inversely, if all the operations are executed successfully the transaction is also succeeded.

Consistency – By consistency in the database what we mean is that any changes in data will lead to the satisfaction of all the constraints applied on that column of a field in a database. For example, when a unique key is assigned to the document inside a collection then the field is always kept unique while maintaining its consistency.

Isolation is the property that helps in explaining the segregate execution of each transaction when multiple transactions are running in the system simultaneously.

Durability – Durability means the changes in the data being made in the database persist and are stored in the backing store as well which means is there is any kind of system failure arising then the data won’t be affected and will be stored and maintained properly.

Working of Transactions

We have to initiate a session in MongoDB with the help of the driver.

Further, you can make use of this session for executing all the operations that you wanted your transaction to carry out. This operation can be having the involvement of multiple documents, collections, and also across sharded clusters and all of them being ACID compliant.

Limitations of using transactions in MongoDB

There are many limitations while using the transactions in MongoDB which are as listed below –

Read operation cannot be performed on system collections.

Write operation cannot be done on non-existing collections or capped collections.

Indexes and collections cannot be modified or dropped in the transactions.


Consider the following example of a transaction in Mongo DB.

The output of the execution of the above code snippet is as shown in the below image –

Further, we can decide if we want to commit the transaction or abort it by using the following statements –



The transactions can be single-document, multi-document, or even involving multiple clusters in it in the case of a distributed system. In Mongo DB the single document transactions are maintained internally. However, in the case of multi-document transactions, there is an extra overhead of managing these transactions. Transactions following the ACID properties make their database consistent, atomic, durable, and isolated. There are multiple methods using which we can initiate the session and abort or commit or transaction in Mongo DB.

Recommended Articles

This is a guide to MongoDB Transactions. Here we discuss the definition, Working of Transactions, examples with code implementation, limitations. You may also have a look at the following articles to learn more –

Attributes Of Matlab Pcolor() With Examples

Introduction to Matlab pcolor()

In MATLAB, pcolor() is the plotting function which is designed to represent the input matrix data in the form of an array of colored cells creating a pseudo color plot. The colored cell is termed as face. The plot gets created as x-y plane flat surface with x and y co-ordinates as vertices(corners) of faces. The limits for x and y co-ordinates are decided by the size of the input matrix.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others


There are different syntaxes that can be used to implement pcolor() method based on the input arguments given to it. Such as:

Where C is the input matrix data


Where C is the input matrix data


X– x-coordinates of the vertices

ax defines the axes targeted for the plot

To store the pseudo color plot as surface object

Attributes of Matlab pcolor()

Here is the table of Attributes:

Attribute Description

C Input matrix data

X,Y coordinates of the vertices

Ax axes targeted for the plot

Examples to Implement Matlab pcolor()

Here are the examples mentioned:

Example #1

create pseudo color plot for input matric Cmat.




Explanation: The input matrix is of size 2X3 and the vertices of the plot is decided 2X3 as default data. The pseudo color plot also can be created in the reverse direction using axis function.

Example #2

Generate Hadamard square orthogonal matrix and create pseudo color plot for same,with the origin set in the upper left corner.


axis square


Explanation: The resultant graph is a 40X40 two-color map, represented in the reverse direction.

Example #3

Create pseudo color plot for the input matrix data Cmat within the defined x and y coordinates given by matrix inputs X and Y.




Explanation: The resultant plot has the vertices as per the values given by X and Y matrices and data from Cmat is plotted within the limits. The data from the input matrix are represented by different color code in the plot.

Example #4

MATLAB supports tilling of plots using the functions like nexttile() and tiledlayout(). The below code is wriiten to create 1X2 chart layout and creating two different pseudo color plot for two different set of inputs and functions in each cell of the layout.



Explantion: The resultant plots are arranged in single layout consisting of two tiles generated using the function nexttile().

Pcolor() with Surface Object

When pcolor() method is assigned to a variable, it returns a surface object. This return value can be used to customize the properties of the plot after its creation.

Example #1

The below code is developed create a pseudo color plot for input matrix and modify the edge color and line width after the plot is generated.


s.LineWidth = 5;


Explanation: The resultant pseudo color plot is assigned to variable ‘s’. The edge color and the line width of the plot is modified using ‘s’ value as shown in the output plot.

Example #2

The below code snippet is designed to create the pseudo color plot and modify the face color of the cells using interpolated coloring using surface object properties.


s.FaceColor = ‘interp’;


Explanation: The resultant pseudo color plot is assigned to surface object ‘s’. The color representation of the faces are modified due to modification applied to the surface object property ‘facecolor’ for the surface object ‘s’.

Semi Logarithm Plotting using pcolor() Example #1

The below MATLAB code is designed to create semi logarithmic pseudo color plot and to alter the appearance using surface object properties from its return value.


s = pcolor(X,YL,Cmat);


Explanation: The resultant output is surface plot where y-coordinate input is the logarithmic function of x-coordinate inputs. The pseudo color semi logarithmic plot generated from the pcolor() method can be stored as surface object and its properties can be altered as shown in the below example:

Example #2




Explanation: The plot from the above code is generated with modified y-tick values by altering the properties of the surface object ‘s’.

Parametric Plotting using pcolor()

Parametric functions are also supported by pcolor() method.

Example #1

The below MATLAB code is designed to generate pseudo color plot from the x-y co oridinates generated from parametric equations.



Explanation: The resultant plot represents the input matrix data, generated from repmat() function within the x-y coordinate values that are defined by two parametric equations.

Note: The size of the x-y coordinate grid must match the size of the input matrix data C. Based on the value in input matrix, the color map array gets colored from its vertices up to face chúng tôi first row gets mapped by the smallest value in C whereas the last row by the largest one, in the color map array. In case of long input array/matrix, the performance of pcolor() method seems to be slower.

Recommended Articles

This is a guide to Matlab pcolor(). Here we discuss an introduction to Matlab pcolor() with appropriate syntax and respective examples for better understanding. You can also go through our other related articles to learn more –

Update the detailed information about A Quick Glance Of Mysql Having With Examples on the website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!