[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] sql select fra to tabeller



Hans Schou wrote:
>> Hej,
>>
>> Hvordan er det lige man laver et (postgresql) select fra to tabeller og
>> får det samlet i en?
>>
>> Jeg vil gerne have:
>>
>>  SELECT dato FROM tabel_a WHERE dato > date('now'); samlet med
>>  SELECT dato FROM tabel_b WHERE dato > date('now');
> 
> Hmm, det ligner en designfejl hvis du har brug for det og ikke kan det.

Måske, de to tabeller er hver sin turnering. Da den ene turnering er en
pokal, er programmet ikke fastlagt. Mens den anden tabel er et fast program.

Her var mit eget forsøg:

"SELECT program2006.dato, pokal2006.dato FROM program2006,pokal2006
WHERE program2006.dato > date('now') AND pokal2006.dato > date('now')
LIMIT 3;"

    dato    |    dato
------------+------------
 2006-05-19 | 2006-05-31
 2006-05-27 | 2006-05-31
 2006-06-05 | 2006-05-31
(3 rows)

Det er så næsten det jeg vil ha'. Det skulle bare være een kolonne, og
kun de 3 første datoer.

>> Så jeg kan have et "ORDER BY dato LIMIT 3" på den samlede tabel.
> 
> Jeg kan ikke se andet end at du skal kopiere til en temporær tabel
> SELECT dato INTO TEMP TABLE mytbl FROM tabel_a LIMIT 3;
> SELECT dato INTO TEMP TABLE mytbl FROM tabel_b LIMIT 3;
> SELECT * FROM mytbl LIMIT 3;

> http://www.postgresql.org/docs/7.4/interactive/sql-selectinto.html

Jeg trode det var noget med JOIN, men jeg fatter hat af manualen :)

http://www.postgresql.org/docs/7.4/interactive/tutorial-join.html

Hum...

psql -d test nobody -c "SELECT dato INTO TEMP TABLE foo FROM program2006
LIMIT 3;
> SELECT dato INTO TEMP TABLE foo FROM pokal2006 LIMIT 3;
> SELECT * FROM foo LIMIT 3;"
ERROR:  Relation 'foo' already exists

Hvad gør jeg galt?


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-06-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *