943,925 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 953
  • MySQL RSS
May 29th, 2009
0

SQL Query not quite pulling the data I expected...

Expand Post »
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)
  1. SELECT products_description.products_name, products_description.products_description, products_description.products_id, products.products_image, products.products_price_sorter
  2. FROM products_description
  3. INNER JOIN (
  4. products, salemaker_sales
  5. ) ON ( products_description.products_id = products.products_id
  6. AND products.master_categories_id = salemaker_sales.sale_categories_selected )
  7. WHERE products.products_status =1
  8. 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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
organicclothes is offline Offline
4 posts
since Jan 2007
May 29th, 2009
0

Re: SQL Query not quite pulling the data I expected...

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:

sql Syntax (Toggle Plain Text)
  1. SELECT pd.products_name,
  2. pd.products_description,
  3. pd.products_id,
  4. p.products_image,
  5. p.products_price_sorter
  6. FROM products_description as pd
  7. INNER JOIN products AS p ON pd.products_id = p.products_id
  8. INNER JOIN salemaker_sales AS ss ON p.master_categories_id = ss.sale_categories_selected )
  9. WHERE p.products_status = 1
  10. 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)
  1. SELECT products_description.products_name, products_description.products_description, products_description.products_id, products.products_image, products.products_price_sorter
  2. FROM products_description
  3. INNER JOIN (
  4. products, salemaker_sales
  5. ) ON ( products_description.products_id = products.products_id
  6. AND products.master_categories_id = salemaker_sales.sale_categories_selected )
  7. WHERE products.products_status =1
  8. 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
pty
Reputation Points: 64
Solved Threads: 39
Posting Pro
pty is offline Offline
530 posts
since Oct 2005
May 29th, 2009
0

Re: SQL Query not quite pulling the data I expected...

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
organicclothes is offline Offline
4 posts
since Jan 2007
May 29th, 2009
0

Re: SQL Query not quite pulling the data I expected...

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.

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
pty
Reputation Points: 64
Solved Threads: 39
Posting Pro
pty is offline Offline
530 posts
since Oct 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Connect to MySQL
Next Thread in MySQL Forum Timeline: Obama's Asking Geeks for Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC