RE: [PHP-DB] union/select statement & number of columns

From: Date: Fri, 19 Oct 2007 15:33:42 +0000
Subject: RE: [PHP-DB] union/select statement & number of columns
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-44236@lists.php.net to get a copy of this message
Unions required that the the queries have the same number of columns and the same data type for each column bastien> To: php-db@lists.php.net> Date: Fri, 19 Oct 2007 09:24:38 -0600> From: bastien> jason.gerfen@scl.utah.edu> Subject: [PHP-DB] union/select statement & number of columns> bastien> > Hello all, I receive an error of the following: The used SELECT> statements have a different bastien> number of columns. Any help, pointers,> tutorials are appreciated.> > Here are the two bastien> tables structure I am trying to pull from:> Table 1> mysql> describe orders;> bastien> +------------+--------------+------+-----+---------+----------------+> | Field | Type | Null | bastien> Key | Default | Extra |> bastien> +------------+--------------+------+-----+---------+----------------+> | id | int(255) | NO | PRI bastien> | | auto_increment |> | ordernum | int(10) | NO | | | |> | date | varchar(60) | NO | | | |> bastien> | time | varchar(20) | NO | | | |> | group | varchar(20) | NO | | | |> | purpose | bastien> varchar(255) | NO | | | |> | tracking | varchar(120) | NO | | | |> | contact | varchar(255) | bastien> NO | | | |> | eta | varchar(50) | NO | | | |> | department | varchar(125) | NO | | | |> | bastien> notes | varchar(255) | NO | | | |> bastien> +------------+--------------+------+-----+---------+----------------+> 11 rows in set (0.01 bastien> sec)> > Table 2> mysql> describe order_items;> bastien> +-------------+---------------+------+-----+---------+----------------+> | Field | Type | Null | bastien> Key | Default | Extra |> bastien> +-------------+---------------+------+-----+---------+----------------+> | id | int(11) | NO | bastien> PRI | | auto_increment |> | ordernum | int(124) | NO | | | |> | quantity | int(124) | NO | | | bastien> |> | description | varchar(124) | NO | | | |> | price | decimal(10,0) | NO | | | |> | bastien> partnum | varchar(255) | NO | | | |> | vendor | varchar(255) | NO | | | |> bastien> +-------------+---------------+------+-----+---------+----------------+> 7 rows in set (0.00 bastien> sec)> > And here is the statement I am using (PHP):> $query = "( SELECT * FROM bastien> orders WHERE ( ordernum LIKE bastien> "$var\" OR> purpose LIKE \"$var\" OR bastien> tracking LIKE \"$var\" OR bastien> contact LIKE> \"$var\" OR bastien> date LIKE \"$var\" OR time bastien> LIKE \"$var\" OR eta LIKE> \"$var\" OR bastien> department LIKE \"$var\" OR bastien> notes LIKE \"$var\" ) AND> bastien> group = \"$group\" ) UNION ( SELECT * FROM bastien> order_items WHERE (> ordernum bastien> LIKE \"$var\" OR price LIKE \"$var\" OR bastien> partnum LIKE> \"$var\" OR bastien> vendor LIKE \"$var\" OR quantityÎ bastien> ÅÇ0ñ¡Â~—Ñ LIKE \"$var\" OR> description LIKE bastien> \"$var\" ) ORDER BY ordernum )";> > -- > PHP bastien> Database Mailing List (http://www.php.net/)> To unsubscribe, visit: bastien> http://www.php.net/unsub.php> _________________________________________________________________ Express yourself with free Messenger emoticons. Get them today! http://www.freemessengeremoticons.ca/?icid=EMENCA122

« previous php.db (#44236) next »