If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Problem with a SELECT

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-12-05, 08:50
Feel11 Feel11 is offline
Registered User
 
Join Date: Dec 2005
Posts: 3
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!
Reply With Quote
  #2 (permalink)  
Old 12-12-05, 19:33
jfulton jfulton is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 12-13-05, 09:08
Feel11 Feel11 is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 12-13-05, 13:22
jfulton jfulton is offline
Registered User
 
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
Reply With Quote
  #5 (permalink)  
Old 12-15-05, 08:05
Feel11 Feel11 is offline
Registered User
 
Join Date: Dec 2005
Posts: 3
Thank you very much jfulton! now it's all work fine!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On