By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

SQL does not support direct operations on matrices, but it does allow easy manipulations with matrices. Learn a few SQL techniques for performing some basic operations on matrices.

WEBINAR:

On-Demand

4) Matrices Multiplication
Two matrices (A and B) can be multiplied if they are compatible, meaning that the first (left) matrix has as many columns as the second (right) matrix has rows. If matrices A and B meet this condition, you can multiply them. The result of such a multiplication will be matrix C, which has as many rows as matrix A and as many columns as matrix B:

Amxn ∙Bnxp = Cmxp

The rules for matrices multiplication are not as trivial as for scalar matrix multiplication. To calculate the ij-element of the product matrix, you need to multiply the ith row vector of the first matrix by the jth column vector of the second matrix. The multiplication of a row vector by a column vector goes as follows:

1. Multiply the first elements of the row and column vectors to get product 1.
2. Multiply the second elements of the row and column vectors to get product 2.
. . . . . . . . . . . . .
N. Multiply the Ns elements of the row and column vectors to get product N.
Lastly, sum up all the products.

Matrices multiplication is not commutative (i.e., A∙B ≠ B∙A). Indeed, in Example 4, the multiplication A3x2 ∙ B2x4 is allowed, because matrices A3x2 and B2x4 are compatible. However, the multiplication B2x4 ∙ A3x2 would be illegal, because the number of columns in the left matrix is not equal to the number of rows in the right matrix. But even if both A∙B and B∙A are compatible, that doesn’t guarantee the same result.

Consider two square matrices:

However, matrices multiplication is associative and distributive:

associative - A∙(B∙C) = (A∙B)∙C

distributive - A∙(B + C) = A∙B + A∙C

distributive - (A + B)C = A∙C + B∙C

5) Matrix Transpose
The transposing of a matrix simply means an exchange between the rows and the columns. Suppose you have an m x n matrix, Amxn. If you transpose that matrix, you will get an n x m matrix, Bnxm, with the following correspondence between the elements of A and B: