Note that there are some explanatory texts on larger screens.

plurals
  1. POMYSQL Sub Select Not Working
    primarykey
    data
    text
    <p>I am trying to run two queries in one. When I run both queries seperatley, they work and provide me with the relevant information I want. When I try to combine them I seem to be going wrong somewhere. Is there something blatantly obvious that I am doing wrong?</p> <pre><code> SELECT pd.product_id, b.product_id, basket_qty, product_name, product_price, product_image, pd.category_id, basket_id (SELECT pd.product_id, b.product_id, basket_session_id, SUM(product_price) AS subtotal FROM basket b, product pd WHERE basket_Session_id = '9htt961lpa1kqieogd5ig5ff93' AND b.product_id = pd.product_id) FROM basket b, product pd, department dep WHERE basket_session_id = '9htt961lpa1kqieogd5ig5ff93' AND b.product_id = pd.product_id AND dep.department_id = pd.category_id </code></pre> <p>Table Structure -</p> <pre><code>CREATE TABLE IF NOT EXISTS `basket` ( `basket_id` int(10) unsigned NOT NULL auto_increment, `product_id` int(10) unsigned NOT NULL, `basket_qty` int(10) unsigned NOT NULL default '1', `basket_session_id` char(32) NOT NULL default '', `basket_date` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`basket_id`), KEY `product_id` (`product_id`), KEY `basket_session_id` (`basket_session_id`) ) CREATE TABLE IF NOT EXISTS `product` ( `product_id` int(10) unsigned NOT NULL auto_increment, `category_id` int(10) unsigned NOT NULL, `department_name` varchar(100) NOT NULL, `product_name` varchar(100) NOT NULL default '', `product_description` text NOT NULL, `product_price` decimal(7,2) NOT NULL default '0.00', `product_qty` smallint(5) unsigned NOT NULL default '0', `product_size` text NOT NULL, `product_image` varchar(200) default NULL, `product_date` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`product_id`), UNIQUE KEY `product_name` (`product_name`), KEY `category_id` (`category_id`) ) CREATE TABLE IF NOT EXISTS `department` ( `department_id` int(10) unsigned NOT NULL auto_increment, `department_parent_id` int(11) NOT NULL default '0', `name` varchar(50) NOT NULL default '', `description` varchar(200) NOT NULL default '', `image` varchar(255) NOT NULL default '', PRIMARY KEY (`department_id`), UNIQUE KEY `name` (`name`), KEY `department_parent_id` (`department_parent_id`) ) </code></pre> <p>I am trying to pull product information based on a "basket" session for an ecommerce application. As a basket can contain more than one product I want to return the SUM of total value from all products.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload