Complex union query

Categories:

Complex union query

Simple sample of a long mysql query I did for a module.

<?php

$sql
= db_query(
               
" SELECT * FROM
                ((SELECT field_pack_upc_value AS upc , nid FROM content_type_bar_code )
                UNION
                (SELECT field_box_upc_value AS upc , nid FROM content_type_bar_code )
                UNION
                (SELECT field_case_upc_value AS upc , nid FROM content_type_bar_code )
                ORDER BY upc, nid ) AS b WHERE SUBSTRING(upc,-6) LIKE '%s'
                AND nid != %d "
               
, $pack, $node->nid );

?>

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
3 + 16 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.