Web Analytics Made Easy -
StatCounter impossible "select statement" need help please - CodingForum


No announcement yet.

impossible "select statement" need help please

  • Filter
  • Time
  • Show
Clear All
new posts

  • impossible "select statement" need help please

    I have a table with 3 simple fields all 2 varchar 1 double.


    I have several diffent distributors listed in my table and some of them carry the same manufacturers products so I am trying to find out which skus are available at more than one distributor and where the cost is best. This is simple enought to do in php but on a select line I am lost. Can this be done or is it impossible?

    Anyhelp greatly appreciated, I read all i could on the mysql site but couldnt find anything related to this scenario.

  • #2
    sql select using group by and having

    The paragraph below is the select statement which will meet the requirements as stated. In the event that there is a need to list all "best prices", even if only one supplier is listed for that sku, the phrase "having count(*) > 1" being eliminated will accomplish that.

    select distributer, manufacturerssku, min(cost) as cost from cost group by manufacturerssku
    having count(*) > 1 and cost=min(cost)

    This statement uses a couple of sql reserved words which are not "just basic sql". The group by reserved word and the having. also the functions count() and min() were used.
    Last edited by fj_sailor; Mar 4, 2004, 03:22 AM.


    • #3
      Thank you very much I was almost ready to split my table in to two.