Thread: MySQL question

Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2010
    Posts
    9
    Plugin Contributions
    0

    Default MySQL question

    Technically this belongs in a MySQL forum but because it is zen cart related I'm hoping to find answers here....

    I load my cart using an easy populate feed. More recently I have begun incorporating automated feeds.

    Easy populate does not load images for categories. I am attempting to write a query that will select ONE image from one product in each category.

    Here is what I have so far:

    SELECT categories_id, products_image
    from zen_products join zen_products_to_categories on
    zen_products.products_id = zen_products_to_categories.products_id
    order by categories_id

    The problem is it selects all images for each category. How can I make it select one image per category?

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,970
    Plugin Contributions
    96

    Default Re: MySQL question

    Try adding " limit 1" to the end of your SQL query.

  3. #3
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: MySQL question

    A more portable form that will work on any server/db would be
    Code:
    SELECT categories_id, products_image
    from ' . TABLE_PRODUCTS . ' p join ' . TABLE_PRODUCTS_TO_CATEGORIES . ' p2c 
    on p.products_id = p2c.products_id
    order by categories_id limit 1
    Last edited by gjh42; 8 Dec 2010 at 04:40 PM.

  4. #4
    Join Date
    Jul 2010
    Posts
    9
    Plugin Contributions
    0

    Default Re: MySQL question

    Sorry, that's not quite what I'm looking for - that only returns one category and one image. I need all categories, but only one product image per category. Sorry if I wasn't more clear on that.

  5. #5
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: MySQL question

    I had a feeling the "limit 1" would not do just what you wanted. I'm not good enough with MySQL yet to say offhand how to do it.

  6. #6
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: MySQL question

    There was a thread a couple/few months ago where a very similar topic was discussed - picking a random product image from each category to display as that category's thumbnail.

 

 

Similar Threads

  1. v154 mysql 5.6 question
    By pixelpadre in forum General Questions
    Replies: 4
    Last Post: 16 Feb 2016, 01:49 PM
  2. find/replace (sub)strings in zen's mysql-DB (mysql syntax question)
    By mypashop in forum Upgrading from 1.3.x to 1.3.9
    Replies: 2
    Last Post: 19 Oct 2007, 02:21 PM
  3. Mysql Question.....
    By SWFW in forum General Questions
    Replies: 6
    Last Post: 22 Nov 2006, 01:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg