Ask a Question related to PostgreSQL / PGSQL, Design and Development.
-
Joost Kraaijeveld #1
SQL query question
Hi all,
I have 2 tables, with a 1-n relation:
parent( oid, parent_name)
child(oid, child_name, iod_parent)
How do I get the parent_names of all parents without a child?
TIA
Groeten,
Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
e-mail: [email]J.Kraaijeveld@Askesis.nl[/email]
web: [url]www.askesis.nl[/url]
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
Joost Kraaijeveld Guest
-
Query Question Please HELP
I have a Table with huge volume of records . table structuer is some thing like this country : region : destrict : destination: Activity date :... -
Query Question
I apologize if this gets posted twice. A lot of my messages are not getting through I could use some help with a query. I have a table called... -
SOS! Query Question
Hi thanks for reading my message. I am totally a novice in coldfusion, just started learning couple of weeks back. I wanted to do a query but I... -
6.1 Query of Query Question. Ref to own Col
Hey I'm running a QoQ using session variables - every thing works fine until I try to refer to a QoQ column. Let me write the example: 1.... -
ASP SQL query question
Greetings, I have a question about a database query from an asp page. My query is functional and produces the data that I need; however, one... -
Tomasz Myrta #2
Re: SQL query question
> Hi all,
select parent_name from parent>
> I have 2 tables, with a 1-n relation:
>
> parent( oid, parent_name)
> child(oid, child_name, iod_parent)
>
> How do I get the parent_names of all parents without a child?
left join child on (parent.oid=child.iod_parent)
where child.oid is null;
or
select parent_name from parent
where not exists (select * from child where
child.iod_parent=parent.oid);
Regards,
Tomasz Myrta
Tomasz Myrta Guest
-
Uwe C. Schroeder #3
SQL query question
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Maybe it's to late for me to think correctly (actually I'm sure of that). I'm
going to ask anyways.
I have a table like
id int4
user_id int4
photo varchar
image_type char(1)
where image_type is either G or X
What I want to do is have ONE query that gives me the count of images of each
type per user_id.
So if user 3 has 5 photos of type G and 3 photos of type X
I basically want to have a result 5,3
It got to be possible to get a query like that, but somehow it eludes me
tonight.
Any pointers are greatly appreciated.
UC
- --
Open Source Solutions 4U, LLC 2570 Fleetwood Drive
Phone: +1 650 872 2425 San Bruno, CA 94066
Cell: +1 650 302 2405 United States
Fax: +1 650 872 2417
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQFCAdOMjqGXBvRToM4RApgvAJsEUsdl6hrVGqRwJ+NI7J rqQqQ5GgCgkTQN
pavTkx47QUb9nr7XO/r/v5k=
=B3DH
-----END PGP SIGNATURE-----
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [email]majordomo@postgresql.org[/email])
Uwe C. Schroeder Guest
-
Jonel Rienton #4
Re: SQL query question
Hi Uwe,
I did a solution for you using PLPgSQL,
create or replace function countem() returns varchar as $$
declare
gcount integer;
xcount integer;
result varchar;
begin
select count(*) into gcount
from pix where image_type = 'G';
select count(*) into xcount
from pix where image_type = 'X';
select gcount || ', ' || xcount
into result;
return result;
end;
$$ LANGUAGE plpgsql;
hope this helps, it's simple and always, there's another (better)
solution
it's my first stab at plpgsql so please bear with me.
-----
Jonel Rienton
[url]http://blogs.road14.com[/url]
Software Developer, *nix Advocate
On Feb 3, 2005, at 1:32 AM, Uwe C. Schroeder wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
> Maybe it's to late for me to think correctly (actually I'm sure of
> that). I'm
> going to ask anyways.
> I have a table like
>
> id int4
> user_id int4
> photo varchar
> image_type char(1)
>
> where image_type is either G or X
> What I want to do is have ONE query that gives me the count of images
> of each
> type per user_id.
> So if user 3 has 5 photos of type G and 3 photos of type X
> I basically want to have a result 5,3
> It got to be possible to get a query like that, but somehow it eludes
> me
> tonight.
>
> Any pointers are greatly appreciated.
>
> UC
>
> - --
> Open Source Solutions 4U, LLC 2570 Fleetwood Drive
> Phone: +1 650 872 2425 San Bruno, CA 94066
> Cell: +1 650 302 2405 United States
> Fax: +1 650 872 2417
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.3 (GNU/Linux)
>
> iD8DBQFCAdOMjqGXBvRToM4RApgvAJsEUsdl6hrVGqRwJ+NI7J rqQqQ5GgCgkTQN
> pavTkx47QUb9nr7XO/r/v5k=
> =B3DH
> -----END PGP SIGNATURE-----
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to
> [email]majordomo@postgresql.org[/email])
>
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [email]majordomo@postgresql.org[/email])
Jonel Rienton Guest
-
Jonel Rienton #5
Re: SQL query question
you're right it's late, i better to get to bed myself, i forgot to
throw in the parameter for the user_id in there, i'm sure you can
figure that one out.
regards,
-----
Jonel Rienton
[url]http://blogs.road14.com[/url]
Software Developer, *nix Advocate
On Feb 3, 2005, at 1:32 AM, Uwe C. Schroeder wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
> Maybe it's to late for me to think correctly (actually I'm sure of
> that). I'm
> going to ask anyways.
> I have a table like
>
> id int4
> user_id int4
> photo varchar
> image_type char(1)
>
> where image_type is either G or X
> What I want to do is have ONE query that gives me the count of images
> of each
> type per user_id.
> So if user 3 has 5 photos of type G and 3 photos of type X
> I basically want to have a result 5,3
> It got to be possible to get a query like that, but somehow it eludes
> me
> tonight.
>
> Any pointers are greatly appreciated.
>
> UC
>
> - --
> Open Source Solutions 4U, LLC 2570 Fleetwood Drive
> Phone: +1 650 872 2425 San Bruno, CA 94066
> Cell: +1 650 302 2405 United States
> Fax: +1 650 872 2417
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.3 (GNU/Linux)
>
> iD8DBQFCAdOMjqGXBvRToM4RApgvAJsEUsdl6hrVGqRwJ+NI7J rqQqQ5GgCgkTQN
> pavTkx47QUb9nr7XO/r/v5k=
> =B3DH
> -----END PGP SIGNATURE-----
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to
> [email]majordomo@postgresql.org[/email])
>
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
Jonel Rienton Guest
-
Roman Neuhauser #6
Re: SQL query question
# [email]uwe@oss4u.com[/email] / 2005-02-02 23:32:28 -0800:
SELECT COUNT(*) FROM t GROUP BY t.user_id, t.image_type> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
> Maybe it's to late for me to think correctly (actually I'm sure of
> that). I'm going to ask anyways. I have a table like
>
> id int4
> user_id int4
> photo varchar
> image_type char(1)
>
> where image_type is either G or X
> What I want to do is have ONE query that gives me the count of images
> of each type per user_id.
> So if user 3 has 5 photos of type G and 3 photos of type X
> I basically want to have a result 5,3
--
If you cc me or remove the list(s) completely I'll most likely ignore
your message. see [url]http://www.eyrie.org./~eagle/faqs/questions.html[/url]
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
[url]http://archives.postgresql.org[/url]
Roman Neuhauser Guest



Reply With Quote

