Syntax of two simple queries
Posted in 1998
Topics: SQL Development & Query Writing, Stored Procedures & SPL
Hi,
In my database is a table with a link to an entry in the table with
organizations and a link to the parent of that organization, in the same
organization table.
Now I don't know what the query should look like...
I tried:
SELECT organization.name, organization.name
FROM organization, parent_organization
WHERE organization.id = parent_organization.id
AND organization.id = parent_organization.parent_id
As this is a sort of hierarchical model, the top knot is a parent of its
own. So organizationX has organizationX as a parent, and this is the
only organization
displayed....
I understood that I could use "aliases" whic should make the query:
SELECT a.organization.name, b.organization.name
FROM organization a, parent_organization b
WHERE a.id = b.id
AND a.id = b.parent_id
I think it's a very simple question, but it's the SQL knowledge I'm
missing....
Another question is:
I try to do the following query (which I thought is plain SQL), but it
results in an error:
SELECT person_id
FROM job_function
GROUP BY person_id
HAVING COUNT(person_id) > 1
(IN N.L.: Give me all person_id's of those rows in the table that have
this person_id more than once, which means, "Give me all persons with
more than one function").
The database complains that the syntax is not OK. It isn't usefull, but
when I put a distinct inside the COUNT, the answer of course is wrong,
but the syntax seems right.... It seems the problem is a COUNT(field) is
not supported, whereas a COUNT(*) is supported.
The database used is a very stripped Informix that was delivered with
the Netscape Enterprise 2.0 webserver, with LiveWire Pro....
Thanks,
George