Thread: SQL question

Page 1 of 7 123 ... LastLast
Results 1 to 10 of 68
  1. #1
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default SQL question

    Is there a way to query the database to list all the different entries from a field in a table and ignore duplicates?

    For example a table with the following entries

    cat
    dog
    cat
    cat
    rabbit
    dog
    elephant
    cat
    cat
    dog
    dog


    would output a list reading

    cat
    dog
    rabbit
    elephant

  2. #2
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,761
    Plugin Contributions
    9

    Default Re: SQL question

    For what reason???
    And is this to be included as some feature in the cart or only for you?

    If in the cart please explain in much more detail what it is you are seeking
    Zen-Venom Get Bitten

  3. #3
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Re: SQL question

    Each product I sell has a model code, this code is often shared by more than one product.

    What I wanted was to list all the different model codes that I have on the store so someone can see at a glance if we stock products for that model code. If they see their model code they can click that code and the site will search the website for that code.

    If you imagine the example I gave earlier and you sold products for different animals, different products could all be found under "cats" I would like a list to be generated for all the different animals I sold products for.

    so even though you may have 1000 products there may only be 15 different animals, so the list i would like generated would be 15 items long listing the different animals, not 1000 items long listing each products animal, resulting in many duplicates.

  4. #4
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,761
    Plugin Contributions
    9

    Default Re: SQL question

    Each product I sell has a model code, this code is often shared by more than one product.
    Shared??

    Is this the same product or a totally different product with the same code?
    Zen-Venom Get Bitten

  5. #5
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Re: SQL question

    different products.

    If you imagine

    Product 1 = Water Bowl - (code = dog)
    Product 2 = Bed - (code = dog)
    Product 3 = toy - (code = cat)
    Product 4 = ball - (code = rabbit)
    Product 5 = ball - (code = dog)
    Product 6 = water bowl - (code = cat)

    list generated

    dog
    cat
    rabbit

    instead of

    dog
    dog
    cat
    rabbit
    dog
    cat

    I want it to list all individual entries in the table field.

  6. #6
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,761
    Plugin Contributions
    9

    Default Re: SQL question

    I suggest that you create/arrange your products in master categories of dog, cat, & rabbit then link them to other areas
    https://www.zen-cart.com/tutorials/i...hp?article=216
    Zen-Venom Get Bitten

  7. #7
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Re: SQL question

    Not applicable.

    Just trying to find a way to query the database to return all the info from a field and filter out duplicates.

  8. #8
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Re: SQL question

    SELECT DISTINCT

    I think that is where I need to start looking

    http://www.tech-recipes.com/rx/1481/...tinct-keyword/

  9. #9
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Re: SQL question

    http://www.w3schools.com/sql/sql_distinct.asp

    I need a php code to make that work

  10. #10
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Re: SQL question

    I'm having trouble writing the php code, can anyone help?

 

 
Page 1 of 7 123 ... LastLast

Similar Threads

  1. v154 SQL Script Question
    By Feznizzle in forum General Questions
    Replies: 2
    Last Post: 2 Jul 2015, 07:13 PM
  2. SQL question
    By timhersh in forum General Questions
    Replies: 14
    Last Post: 1 Oct 2012, 10:12 PM
  3. SQL question
    By pixelpadre in forum General Questions
    Replies: 9
    Last Post: 26 Apr 2012, 02:14 PM
  4. v139h SQL question... help please!
    By Feznizzle in forum General Questions
    Replies: 4
    Last Post: 3 Mar 2012, 10:31 PM
  5. SQL Question Deleting zones
    By kitcorsa in forum General Questions
    Replies: 2
    Last Post: 12 May 2008, 12:37 PM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR