/* Examples of new SQL */

/* Related object count */
SELECT
    COUNT( ezcontentobject.id ) AS count
FROM
    ezcontentobject, ezcontentobject_link
WHERE
    ezcontentobject.id = ezcontentobject_link.to_contentobject_id AND
    ezcontentobject.status = 1 AND
    ezcontentobject_link.id IN
    (
        SELECT DISTINCT
        ezcontentobject_link.id
        FROM
        ezcontentobject, ezcontentobject_link
        WHERE
        ezcontentobject.id = ezcontentobject_link.from_contentobject_id AND
        ezcontentobject.status = 1 AND
        ezcontentobject_link.op_code = 0
        AND ezcontentobject_link.from_contentobject_id=1237
        AND ezcontentobject_link.from_contentobject_version=3
        AND ( relation_type & 15 ) <> 0
    );

/* Reverse related object count */
SELECT
    COUNT( ezcontentobject.id ) AS count
FROM
    ezcontentobject, ezcontentobject_link
WHERE
    ezcontentobject.id = ezcontentobject_link.from_contentobject_id AND
    ezcontentobject.status = 1 AND
    ezcontentobject_link.id IN
    (
        SELECT DISTINCT
        ezcontentobject_link.id
        FROM
        ezcontentobject, ezcontentobject_link
        WHERE
        ezcontentobject.id = ezcontentobject_link.from_contentobject_id AND
        ezcontentobject.status = 1 AND
        ezcontentobject_link.op_code = 0
        AND ezcontentobject_link.to_contentobject_id = 1237 AND
        ezcontentobject_link.from_contentobject_version=ezcontentobject.current_version
        AND ( relation_type & 15 ) <> 0
    );



/* Related object id, status and name (for debugging) */
SELECT
    ezcontentobject.id,ezcontentobject.status,ezcontentobject.name
FROM
    ezcontentobject, ezcontentobject_link
WHERE
    ezcontentobject.id = ezcontentobject_link.to_contentobject_id AND
    ezcontentobject.status = 1 AND
    ezcontentobject_link.id IN
    (
        SELECT DISTINCT
        ezcontentobject_link.id
        FROM
        ezcontentobject, ezcontentobject_link
        WHERE
        ezcontentobject.id = ezcontentobject_link.from_contentobject_id AND
        ezcontentobject.status = 1 AND
        ezcontentobject_link.op_code = 0
        AND ezcontentobject_link.from_contentobject_id=1237
        AND ezcontentobject_link.from_contentobject_version=3
        AND ( relation_type & 15 ) <> 0
    );

/* Reverse related object id, status and name (for debugging) */
SELECT
    ezcontentobject.id,ezcontentobject.status,ezcontentobject.name
FROM
    ezcontentobject, ezcontentobject_link
WHERE
    ezcontentobject.id = ezcontentobject_link.from_contentobject_id AND
    ezcontentobject.status = 1 AND
    ezcontentobject_link.id IN
    (
        SELECT DISTINCT
        ezcontentobject_link.id
        FROM
        ezcontentobject, ezcontentobject_link
        WHERE
        ezcontentobject.id = ezcontentobject_link.from_contentobject_id AND
        ezcontentobject.status = 1 AND
        ezcontentobject_link.op_code = 0
        AND ezcontentobject_link.to_contentobject_id = 1237 AND
        ezcontentobject_link.from_contentobject_version=ezcontentobject.current_version
        AND ( relation_type & 15 ) <> 0
    );
