Re: [SQL] sub query and AS

2012-05-24 Thread Samuel Gendler
On Wed, May 23, 2012 at 12:07 PM, Lee Hachadoorian < lee.hachadooria...@gmail.com> wrote: > On Wed, May 23, 2012 at 5:24 AM, Ferruccio Zamuner > wrote: > > Hi, > > > > I like PostgreSQL for many reasons, one of them is the possibility to use > > sub query everywhere. Now I've found where it doesn

Re: [SQL] sub query and AS

2012-05-23 Thread Lee Hachadoorian
On Wed, May 23, 2012 at 5:24 AM, Ferruccio Zamuner wrote: > Hi, > > I like PostgreSQL for many reasons, one of them is the possibility to use > sub query everywhere. Now I've found where it doesn't support them. > > I would like to use a AS (sub query) form. > > This is an example: > > First the s

[SQL] sub query and AS

2012-05-23 Thread Ferruccio Zamuner
Hi, I like PostgreSQL for many reasons, one of them is the possibility to use sub query everywhere. Now I've found where it doesn't support them. I would like to use a AS (sub query) form. This is an example: First the subquery: select substr(descr, 7, length(descr)-8) from (select string

Re: [SQL] Sub-query as function argument

2005-12-20 Thread Tom Lane
Michael Burke <[EMAIL PROTECTED]> writes: > Is it possible to execute a SELECT query as an argument to a function? > SELECT my_func('Sample', NULL, SELECT MIN(year) FROM audio); You need parentheses around the sub-SELECT. SELECT my_func('Sample', NULL, (SELECT MIN(year) FROM audio)); This is

Re: [SQL] Sub-query as function argument

2005-12-20 Thread Michael Burke
On December 20, 2005 10:52 am, Jaime Casanova wrote: > have you tried? Yes: => SELECT my_func('Sample', NULL, SELECT MIN(year) FROM audio); ERROR: syntax error at or near "SELECT" at character 32 PostgreSQL 7.4.9, myfunc is pl/pgsql. Just found a working method, though: => SELECT my_func('Sam

Re: [SQL] Sub-query as function argument

2005-12-20 Thread Jaime Casanova
On 12/20/05, Michael Burke <[EMAIL PROTECTED]> wrote: > Is it possible to execute a SELECT query as an argument to a function? > have you tried? -- regards, Jaime Casanova (DBA: DataBase Aniquilator ;) ---(end of broadcast)--- TIP 2: Don't 'kill -9

[SQL] Sub-query as function argument

2005-12-20 Thread Michael Burke
Is it possible to execute a SELECT query as an argument to a function? Example: SELECT my_func('Sample', NULL, SELECT MIN(year) FROM audio); In my particular case, my_func inserts columns into another table; I wish to use values from another table as the arguments. The interior SELECT will re

Re: [SQL] sub query

2003-09-20 Thread Peter Eisentraut
Martin Kuria writes: > Hi again I have this problem when I try to run this query, how can I rewrite > it for it to work. > > SELECT o.item_order_num,SUM(o.item_quantity + o.item_product_id) As total, > o.item_status > FROM soko_product p, soko_ordered_item o > WHERE p.product_id = o.item_product_i

[SQL] sub query

2003-09-20 Thread Martin Kuria
] ++ From: Christoph Haller <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] CC: [EMAIL PROTECTED] Subject: Re: [SQL] sub query Date: Wed, 17 Sep 2003 10:54:49 +0200 > > > Hi I have this problem, when I try to run this query: > > > > SELECT MAX(d), host_position FROM (SELE

Re: [SQL] sub query

2003-09-17 Thread Christoph Haller
The reason why the first one SELECT MAX(e.d), e.host_position FROM (SELECT host_position, COUNT(host_position) as d FROM sss_host GROUP BY host_position) as e GROUP BY e.host_position ORDER BY 1 LIMIT 1; did not work is because the query needs a ORDER BY 1 DESC LIMIT 1 like the second one. Mind the

Re: [SQL] sub query

2003-09-17 Thread Martin Kuria
ED] CC: [EMAIL PROTECTED] Subject: Re: [SQL] sub query Date: Wed, 17 Sep 2003 10:54:49 +0200 > > > Hi I have this problem, when I try to run this query: > > > > SELECT MAX(d), host_position FROM (SELECT host_position, > > COUNT(host_position) as d FROM sss_host GROUP B

Re: [SQL] sub query

2003-09-17 Thread Christoph Haller
> > > Hi I have this problem, when I try to run this query: > > > > SELECT MAX(d), host_position FROM (SELECT host_position, > > COUNT(host_position) as d FROM sss_host GROUP BY host_position) as e; > > > > am getting and ERROR: Attribute e.host_position must be GROUPed or > used in > > an aggregat

Re: [SQL] sub query

2003-09-17 Thread Christoph Haller
> Hi I have this problem, when I try to run this query: > > SELECT MAX(d), host_position FROM (SELECT host_position, > COUNT(host_position) as d FROM sss_host GROUP BY host_position) as e; > > am getting and ERROR: Attribute e.host_position must be GROUPed or used in > an aggregate function. > > Pl

[SQL] sub query

2003-09-17 Thread Martin Kuria
Hi I have this problem, when I try to run this query: SELECT MAX(d), host_position FROM (SELECT host_position, COUNT(host_position) as d FROM sss_host GROUP BY host_position) as e; am getting and ERROR: Attribute e.host_position must be GROUPed or used in an aggregate function. Please to advic

[SQL] sub query

2003-09-17 Thread Martin Kuria
Hi I have this problem, when I try to run this query: SELECT MAX(d), host_position FROM (SELECT host_position, COUNT(host_position) as d FROM sss_host GROUP BY host_position) as e; am getting and ERROR: Attribute e.host_position must be GROUPed or used in an aggregate function. Please to advic

Re: [SQL] sub-query optimization

2003-02-14 Thread Brad Hilton
On Fri, 2003-02-14 at 04:59, Tomasz Myrta wrote: > Brad Hilton wrote: > > > select * from articles where exists > > (select 1 from article_categories, categories, category_map > >where > >article_categories.article_id = articles.id and > >categories.restrict_views = FALSE and > >

Re: [SQL] sub-query optimization

2003-02-14 Thread Brad Hilton
On Fri, 2003-02-14 at 14:08, Tom Lane wrote: > Brad Hilton <[EMAIL PROTECTED]> writes: > > ... If I modify the query slightly: > > > > > select 1 from article_categories > > --> > > select 1 from articles, article_categories > > - > > > the query takes 98 msec. > > Yeah, becau

Re: [SQL] sub-query optimization

2003-02-14 Thread Stephan Szabo
On 14 Feb 2003, Brad Hilton wrote: > I am hoping someone can help explain why modifying the following query > can effect such a huge change in speed. The query is: > > select * from articles > where exists >( select 1 from article_categories > where > articl