Hi,
Some ways to do that:
http://www.sql-ex.ru/help/select16.php
> Hi list,
> I have two table that are so represented:
> t1:
> id int primary key
> ... other
> t2:
> id int primary key
> t1id int fk(t1.id)
> somedate date
> ... other
> data t1:
> 1 | abcde
> 2 | fghi
> data t2:
> 1 | 1 | 2010-05-
In article <4bfd5bc0.90...@unipex.it>,
Michele Petrazzo - Unipex writes:
> Hi list,
> I have two table that are so represented:
> t1:
> id int primary key
> ... other
> t2:
> id int primary key
> t1id int fk(t1.id)
> somedate date
> ... other
> data t1:
> 1 | abcde
> 2 | fghi
> data t2:
> 1 |
I found a good solution.
drop table if exists t3;
drop table if exists t2;
drop table if exists t1;
create table t1 ( id int primary key, title varchar(10) );
insert into t1 values (1,'abcde'),(2,'fghi');
create table t2 (id int primary key,t1id int not null references t1 (id)
,somedate date);
in
Michele Petrazzo - Unipex wrote:
> I have two table that are so represented:
> t1:
> id int primary key
> ... other
> t2:
> id int primary key
> t1id int fk(t1.id)
> somedate date
> ... other
> data t1:
> 1 | abcde
> 2 | fghi
> data t2:
> 1 | 1 | 2010-05-23
> 2 | 1 | 2010-05-24
> 3 | 1 | 2010-
Hello
Here a suggestion for your problem.
SELECT a.id AS t1_id, d.id AS t2_id, d.somedate AS t2_somedate
FROM t1 a
JOIN
(
SELECT id, t1id, somedate
FROM t2 b
WHERE (t1id, somedate) IN
(
SELECT t1id, somedate
FROM t2 c
WHERE c.t1id = b.t1id
ORDE
I can only see a LIMIT 1 possible. If someone can come up with LIMIT N on this
one, please let us all know.
rolando=# drop table if exists t2;
DROP TABLE
rolando=# drop table if exists t1;
DROP TABLE
rolando=# create table t1 ( id int primary key, title varchar(10) );
NOTICE: CREATE TABLE / PRIM