SQL question regarding a couple of table joins.

Поиск
Список
Период
Сортировка
Искать

SQL question regarding a couple of table joins.

От:
Warren Vanichuk <pyber@street-light.com>
Дата:

Greetings.

We three have three tables, a links table which stores basic information
about a link, a linksdetail table which stores more detailed information
about the link, and a linkdaystats table which records the daily statistical
information on the link.

My problem is, once a day I want to delete everything in that table to start
afresh.  Any information accumulated in the linkdaystats table has been
parsed, multilated, spindled, whatever, and done with, do I merely do a
'drop from linkdaystats' to start afresh.  The only issue is this causes
other queries to break, suck as the only below :

SELECT                                                                                                                               links.linkid,                                                                                                                       links.linkurl,links.linktext,links.bannerid,linkdaystats.linkid
FROM   links, linkdetail ,   linkdaystats
WHERE     links.linkid = linkdetail.linkid                                     

----linkid | linkurl | linktext | bannerid | linkid 
--------+---------+----------+----------+--------
(0 rows)
----

Help?  :)  This is PostGreSQL 7.0.2 on Debian 2.2/Linux-2.2.17 (Kernel/PGSQL
from source)

--- Table information :

freehost=# \d links                                Table "links"Attribute |     Type     |                      Modifier                      
-----------+--------------+----------------------------------------------------linkid    | integer      | not null default nextval('links_linkid_seq'::text)linkurl   | varchar(255) | linktext  | varchar(255) | bannerid  | integer      | 
Index: links_linkid_key

freehost=# \d linkdetail            Table "linkdetail"    Attribute     |     Type     | Modifier 
-------------------+--------------+----------linkid            | integer      | referrer          | varchar(255) | maxclicks         | integer      | maximpressions    | integer      | primarycategory   | integer      | secondarycategory | integer      | tertiarycategory  | integer      | weight            | float4       | starttime         | timestamp    | stoptime          | timestamp    | 

freehost=# \d linkdaystats       Table "linkdaystats" Attribute  |   Type    | Modifier 
-------------+-----------+----------linkid      | integer   | datestamp   | timestamp | clicks      | bigint    | impressions | bigint    | 


Sincerely, Warren


RE: SQL question regarding a couple of table joins.

От:
"Edmar Wiggers" <edmar@brasmap.com>
Дата:
> SELECT
>
>  links.linkid,
>
>  links.linkurl,
>  links.linktext,
>  links.bannerid,
>  linkdaystats.linkid
> FROM
>  links,
>  linkdetail ,
>  linkdaystats
> WHERE
>       links.linkid = linkdetail.linkid

I guess you have forgot to include: "links.linkid = linkdaystats.linkid"

Moreover, if table linkdaystats is empty that query will return NOTHING. The
solution is to remove linkdaystats from the query, or wait for 7.1 and use
OUTER JOINs.

Yours sincerely,

Edmar Wiggers
BRASMAP Information Systems
+55 48 9960 2752


FAQ