Need query

Started by Gaurav Jindalabout 12 years ago2 messagesgeneral
Jump to latest
#1Gaurav Jindal
gaurjin@gmail.com

Can anybody help me with query-

I have 3 tables- a,b,c

a has relation with b and b has relation with c
a does not have a relation with c

I need to find top performing item in table 'a'. It is based on count. If
more count, it is top performing. We can count only based on actions in
table 'c'. I can put 'where' clause in table 'c' and find those values. I
can't join table 'a' and 'c' as they don't have any relation.

select b.top
FROM b,c
WHERE c.action IN ('blah', 'blah', 'any values') and b.id = c.id;

'top' in the query is a common column in table 'a' named 'a_top'. We need
to count column 'track' in table 'a' based on this information.

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: Gaurav Jindal (#1)
Re: Need query

Gaurav Jindal wrote

a has relation with b and b has relation with c

Given this statement what specifically are you having difficulty with. You
are allowed to perform multiple joins, whether explicit or via FROM/WHERE,
in the same query.

SELECT ...
FROM a,b,c
WHERE a=b and b=c

OR

SELECT ...
FROM c
JOIN b on c=b
JOIN a ON b=a

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Need-query-tp5799681p5799694.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general