| | |
SQL Query not quite pulling the data I expected...
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2007
Posts: 4
Reputation:
Solved Threads: 0
Hi,
I've managed to piece together an SQL query (not literate in the language), but it isn't giving quite the data I expected. Here is the code:
The trouble I am seeing is this:
salemaker_sales.sale_categories_selected contains multiple variables separated by a comma
This query is only returning the first variable. What am I missing?
Any help much appreciated,
Audra
I've managed to piece together an SQL query (not literate in the language), but it isn't giving quite the data I expected. Here is the code:
MySQL Syntax (Toggle Plain Text)
SELECT products_description.products_name, products_description.products_description, products_description.products_id, products.products_image, products.products_price_sorter FROM products_description INNER JOIN ( products, salemaker_sales ) ON ( products_description.products_id = products.products_id AND products.master_categories_id = salemaker_sales.sale_categories_selected ) WHERE products.products_status =1 AND salemaker_sales.sale_status = "1"
The trouble I am seeing is this:
salemaker_sales.sale_categories_selected contains multiple variables separated by a comma
This query is only returning the first variable. What am I missing?
Any help much appreciated,
Audra
Not really sure what you're asking. What column type is sales_categories?
Also your SQL is confusing; try aliasing the table names and aligning it:
Also your SQL is confusing; try aliasing the table names and aligning it:
sql Syntax (Toggle Plain Text)
SELECT pd.products_name, pd.products_description, pd.products_id, p.products_image, p.products_price_sorter FROM products_description as pd INNER JOIN products AS p ON pd.products_id = p.products_id INNER JOIN salemaker_sales AS ss ON p.master_categories_id = ss.sale_categories_selected ) WHERE p.products_status = 1 AND ss.sale_status = 1
•
•
•
•
Hi,
I've managed to piece together an SQL query (not literate in the language), but it isn't giving quite the data I expected. Here is the code:
MySQL Syntax (Toggle Plain Text)
SELECT products_description.products_name, products_description.products_description, products_description.products_id, products.products_image, products.products_price_sorter FROM products_description INNER JOIN ( products, salemaker_sales ) ON ( products_description.products_id = products.products_id AND products.master_categories_id = salemaker_sales.sale_categories_selected ) WHERE products.products_status =1 AND salemaker_sales.sale_status = "1"
The trouble I am seeing is this:
salemaker_sales.sale_categories_selected contains multiple variables separated by a comma
This query is only returning the first variable. What am I missing?
Any help much appreciated,
Audra
Note to self... pocket cup
•
•
Join Date: Jan 2007
Posts: 4
Reputation:
Solved Threads: 0
Thank you pty, what you have done is certainly easier to follow. Running that query leads to the same result I experienced.
The sales_categories column is a text type column.
In this instance, the result will only lead to one entry w/ the data "48,76,129"
Each of those numbers corresponds to a p.master_categories_id
The results yield the products in p.master_categories_id 48 and then stops there.
I'm guessing the problem lies in the fact that this is a text field?
I apologize if my description is confusing. I do not have the SQL lingo, so I speak in laymens' terms.
Peace,
Audra
The sales_categories column is a text type column.
In this instance, the result will only lead to one entry w/ the data "48,76,129"
Each of those numbers corresponds to a p.master_categories_id
The results yield the products in p.master_categories_id 48 and then stops there.
I'm guessing the problem lies in the fact that this is a text field?
I apologize if my description is confusing. I do not have the SQL lingo, so I speak in laymens' terms.
Peace,
Audra
I misunderstood your first post.
If the column is varchar and you have a comma separated list of IDs there isn't a clean way of joining.
You should review your table design and possibly introduce a link table (many to many relationship). I don't know exactly how your data is meant to be so I can't suggest exactly what to do, but rather than having many items in a list inside one column you should organise your data so each list item is a row.
If the column is varchar and you have a comma separated list of IDs there isn't a clean way of joining.
You should review your table design and possibly introduce a link table (many to many relationship). I don't know exactly how your data is meant to be so I can't suggest exactly what to do, but rather than having many items in a list inside one column you should organise your data so each list item is a row.
•
•
•
•
Thank you pty, what you have done is
certainly easier to follow. Running that query leads to the same result I experienced.
The sales_categories column is a text type column.
In this instance, the result will only lead to one entry w/ the data "48,76,129"
Each of those numbers corresponds to a p.master_categories_id
The results yield the products in p.master_categories_id 48 and then stops there.
I'm guessing the problem lies in the fact that this is a text field?
I apologize if my description is confusing. I do not have the SQL lingo, so I speak in laymens' terms.
Peace,
Audra
Note to self... pocket cup
![]() |
Similar Threads
- sql query problem with MS Access and C# (C#)
- how to delete duplicate record in a table by using SQL query (MS SQL)
- Read multiple column data from SQL query ( 1 row ) (ASP.NET)
- I am working on an ASP.net 2.0 application written in C#, pulling data from an Oracle (Oracle)
- SQL Query Analyzer Problem (Database Design)
- retrieving a particular value with a sql query (PHP)
- SQL Query Syntax (MySQL)
- SQL query problem with WHERE clause (ASP)
- SQL search query (PHP)
- C# VS 2005 - SQL Query Parameters to an ODBC DataSource (C#)
Other Threads in the MySQL Forum
- Previous Thread: Connect to MySQL
- Next Thread: Obama's Asking Geeks for Help
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gartner gnu government gpl greenit groupware hiring hyperic images innerjoins insert ip joebrockmeier join keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization





