| POSTGRESQL | MYSQL | |
| ANSI SQL compliance | Closer to ANSI SQL standard | Follows some of the ANSI SQL standards |
| Performance | Slower | Faster |
| Sub-selects | Yes | No |
| Transactions | Yes | Yes, however InnoDB table type must be used |
| Database replication | Yes | Yes |
| Foreign key support | Yes | No |
| Views | Yes | No |
| Stored procedures | Yes | No |
| Triggers | Yes | No |
| Unions | Yes | No |
| Full joins | Yes | No |
| Constraints | Yes | No |
| Windows support | Yes | Yes |
| Vacuum (cleanup) | Yes | No |
| ODBC | Yes | Yes |
| JDBC | Yes | Yes |
| Different table types | No | Yes |
Saturday, January 22, 2011
POSTGRESQL vs MYSQL
Monday, January 3, 2011
SQL UNION
The UNION operator is used to combine the result-set of two or more SELECT statements.
Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order.
syntax 1.
SELECT column_name(s) FROM table_name1
UNION
SELECT column_name(s) FROM table_name2
syntax 2.
SELECT column_name(s) FROM table_name1
UNION ALL
SELECT column_name(s) FROM table_name2
Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order.
syntax 1.
SELECT column_name(s) FROM table_name1
UNION
SELECT column_name(s) FROM table_name2
syntax 2.
SELECT column_name(s) FROM table_name1
UNION ALL
SELECT column_name(s) FROM table_name2
SQL Joins
SQL joins are used to query data from two or more tables, based on a relationship between certain columns in these tables.
1.The INNER JOIN keyword return rows when there is at least one match in both tables.
SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name
2.The LEFT JOIN keyword returns all rows from the left table (table_name1), even if there are no matches in the right table (table_name2).
SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
3.The RIGHT JOIN keyword Return all rows from the right table (table_name2), even if there are no matches in the left table (table_name1).
SELECT column_name(s)
FROM table_name1
RIGHT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
4.The FULL JOIN keyword return rows when there is a match in one of the tables.
SELECT column_name(s)
FROM table_name1
FULL JOIN table_name2
ON table_name1.column_name=table_name2.column_name
1.The INNER JOIN keyword return rows when there is at least one match in both tables.
SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name
2.The LEFT JOIN keyword returns all rows from the left table (table_name1), even if there are no matches in the right table (table_name2).
SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
3.The RIGHT JOIN keyword Return all rows from the right table (table_name2), even if there are no matches in the left table (table_name1).
SELECT column_name(s)
FROM table_name1
RIGHT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
4.The FULL JOIN keyword return rows when there is a match in one of the tables.
SELECT column_name(s)
FROM table_name1
FULL JOIN table_name2
ON table_name1.column_name=table_name2.column_name
Subscribe to:
Posts (Atom)