Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2005
    Posts
    3

    Unanswered: Problem with a SELECT

    Hello guys, this is my situation:
    I Have the following tables;

    Articles (Idarticlers#, PinV)
    Sellers (PinV#, Name)

    and i have to select the list of the Name of the sellers who have more Articles (in order)

    what can i do?

    thank you!
    and sorry for my english!

  2. #2
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    Code:
    SELECT 
         s.Name
         , (SELECT COUNT(*) FROM Articles a WHERE a.Pin = s.Pin) AS NumArticles
    FROM
         Sellers s
    GROUP BY
         s.Pin
    ORDER BY
         NumArticles DESC

  3. #3
    Join Date
    Dec 2005
    Posts
    3
    Thank you Very much jfulton!!
    It works great!

    I have a last question: how i can do to add the count(*) from two select?
    my situation is this:

    SELECT 4*COUNT(*) from Sell where month(date) = 10 and year(date) = 2005 + SELECT 12*COUNT(*) from services where month(date) = 10 and year(Date) = 2005

    the + doesn't works i see...so what can i do?

    greets
    Fill

  4. #4
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    If you want to retrieve a sum, the + should come in the select statement. ie.

    Code:
    SELECT 4+1 AS five
    or
    Code:
    SELECT ( (SELECT COUNT(*) FROM table1) + (SELECT MAX(field) FROM table2) ) AS sum
    You can nest statements in your queries for more complexity. Judging from the query you replied with, you may also want to read up on other functions like SUM() and DATE_FORMAT().

    http://dev.mysql.com/doc/refman/5.0/en/index.html

  5. #5
    Join Date
    Dec 2005
    Posts
    3
    Thank you very much jfulton! now it's all work fine!

Posting Permissions

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