Απορία SQL

V13 v13 at v13.gr
Mon Feb 7 18:21:03 EET 2011


On Monday 07 of February 2011, Antonis Christofides wrote:
> CREATE TABLE wiki_page(
> id INTEGER NOT NULL PRIMARY KEY,
> "name" VARCHAR(100) NOT NULL
> );
> 
> CREATE TABLE wiki_pageversion(
> page INTEGER NOT NULL REFERENCES wiki_page(id),
> version_number INTEGER NOT NULL,
> content TEXT NOT NULL,
> CONSTRAINT pk PRIMARY KEY (page, version_number)
> );

An den skeytomai kati lathos, to parakato kanei ayto poy theleis:

SELECT a.id, MAX(b.version_number) FROM wiki_page a
  LEFT JOIN wiki_pageversion b ON a.id=b.page
  GROUP BY a.id;

kai isos na einai pio grigoro.

Se postgresql yparxei h 'EXPLAIN' h opoia mporei na soy pei poia apo tis dyo 
einai h pio grigori. An den exei kati antistoixo h mysql, bale postgres kai 
kane tis dokimes ekei. To apotelesma bebaia tha einai me bash ton optimizer 
ths postgres alla mias kai to erotima einai aplo *ypotheto* pos tha isxyei to 
idio kai se mysql.


More information about the Linux-greek-users mailing list