Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

mysql discount and count to be used in same query

Posted on 2012-03-24
2
Medium Priority
?
499 Views
Last Modified: 2012-04-04
i have this query

select distinct(origin) from names order by id desc

now, i want to apply the count also to this query to actually count the pictures in the query

the pictures table is different and origin is the field which matches in names table and the pictures table

so how can i do it

any idea
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37760769
select COUNT(*), distinct(origin) from names order by id desc
0
 
LVL 24

Accepted Solution

by:
johanntagle earned 2000 total points
ID: 37761947
select origin, count(id) from names group by origin;

Note that you cannot really effectively order by a column outside origin and count(id) because you already aggregated rows here.  Now if you want to join it with data with you pictures table you need something like:

select p.column1, count(n.id) from pictures p join names n on p.origin=n.origin group by p.column1

if you need to add more columns, just make sure you add them to both the select and group by clauses.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
What we learned in Webroot's webinar on multi-vector protection.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question