Table comparison - sql, PL-SQL Programming

Table Comparison - SQL

The following definitions for relation comparisons:

Let r1 and r2 be relations having the same heading. Then:

r1 ⊆ r2 is true if every tuple of r1 is also a tuple of r2, otherwise false.

r1 ⊇ r2 is equivalent to r2 ⊆ r1

r1 = r2 is equivalent to r1 ⊆ r2 AND r2 ⊆ r1

The question arises as to whether SQL tables can be similarly compared. SQL does not have direct counterparts of ⊆ and ⊇. It does of course have =, but table expressions cannot be used as comparands. However, as we have seen in Examples et seq., the operator TABLE has been available since SQL: 2003 to derive from a given table expression a value of a multiset type whose element type is a row type. In other words, (SELECT * FROM t1) = (SELECT * FROM t2) is illegal but we can obtain the required effect by writing TABLE (SELECT * FROM t1) = TABLE (SELECT * FROM t2). So, to compare two tables, we have to use an operator named TABLE to "convert" them from tables into multisets of rows!

To test for every row of t1 being also a row of t2 we could write, for example, NOT EXISTS (SELECT * FROM t1 EXCEPT SELECT * FROM t2). In fact, SQL's NOT EXISTS is an exact counterpart of Tutorial D's IS_EMPTY operator. However, note carefully that the case where every row in t1 appears in t2 and every row of t2 appears in t1 does not guarantee that t1 and t2 are the same table. Row r might appear twice in t1 but only once in t2, for example.

Posted Date: 1/18/2013 7:02:48 AM | Location : United States







Related Discussions:- Table comparison - sql, Assignment Help, Ask Question on Table comparison - sql, Get Answer, Expert's Help, Table comparison - sql Discussions

Write discussion on Table comparison - sql
Your posts are moderated
Related Questions
Using FOR UPDATE If you declare a cursor which will be referenced in the CURRENT OF clause of an UPDATE or DELETE statement, you should use the FOR UPDATE clause to obtain an

Using Invoker Rights: By default, the stored procedure executes with the privileges of its definer, not its invoker. These procedures are bound to the schema in which they inh

Using INNER JOIN INNER JOIN is used to retrieve the data from all tables listed based on a condition of equality listed after keyword ON. If the condition is not meet, rows ar

Authorize and fetch data from Instagram Project Description: Incorporate Instagram feed on mobile site platform: c#, ms sql, jquerymobile, jquery Web admin Author

Third Step at defining type SID in SQL CREATE DOMAIN SID AS VARCHAR(5) CHECK ( VALUE IS NOT NULL AND SUBSTRING(VALUE FROM 1 FOR 1) = 'S' AND CAST('+'||SUBSTRING(VALUE

Example of GROUPBY Operator Example: How many students sat each exam, using GROUP BY, NATURAL LEFT JOIN, and COALESCE SELECT CourseId, COALESCE (n, 0) AS n FROM COURS

GOTO Statement   The GOTO statement branches categorically to a block label or statement label. The label should be exclusive within its scope and should precede a PL/SQL bloc

Processing Transactions This part describes how to do the transaction processing. You learn the fundamental techniques that safeguard the consistency of your database, involvin

Write SQL queries to solve the following specifications. Include the query AND THE OUTPUT.  A screen dump of the output is acceptable. Show as many rows as you can. A screen dump i

Implicit Cursor Attributes The Implicit cursor attributes returns the information about the execution of an INSERT, DELETE, UPDATE, or SELECT INTO statement. The cursor attribu