views:

81

answers:

3

Table1 t10 (id)

id
---
1
2

table t11(a1,a2,a3)

a1  a2  a3
----------
1   10   a
1   10   b
1   11   b
1   12   c
2   20   d
2   21   e

select * from t10 a,t11 b where a.id = b.a1 how to display

id  a1  a2  a3
--------------
1   1   10  a
1   1   10  b //(not display this row)
1   1   11  b //(not display this row)
1   1   12  c //(not display this row) 
2   2   20  d
2   2   21  e //(not display this row)

just get t11's random row

maybe display this
id  a1  a2 
---------- 
1   1   11  b
1   1   10  a //(not display this row)
1   1   10  b //(not display this row)
1   1   12  c //(not display this row) 
2   2   20 
2   2   21  //(not display this row)
+3  A: 
select a1 as id, a1, min(a2) as a2
from t11
group by a1

will give you:

id  a1  a2
----------
1   1   10
2   2   20
davek
Yes, but he states, though it is hard to make out, that we wants the first row inserted in the table (e.g. a2=11 for id=1) but obviously he really needs some other factor in determining which row he specifically wants other then the way they were inserted in the table.
Kitson
yeah ! Kitson see it
shuc
A: 
select *
  from t10 a,
       (select * from (select b.*, row_number() over(partition by a10 order by a10) as rn
          from t11 b) where rn =1) b
 where a.id = b.a10(+)

yeah! it's answer!

shuc
Please don't post *answers* when you want to add information. You can edit your question (and please do, it's missing some information), or add *comments* to answers you recieved (like this, here). Welcome.
Kobi
Don't write an answer unless it is an answer. Comment on other answers or update your question. Also, you keep reversing the 10 and 11 in t11 for column b.
ck
yeah i am sorry, first time ask qustion here
shuc
A: 

This seems almost like he wants something like FIRST/LAST from ms access.

This can ben done (very closely) in Sql Server using

DECLARE @Table TABLE(
     id INT,
     a1 INT,
     a2 INT
)

INSERT INTO @Table (id,a1,a2) SELECT 1, 1, 11
INSERT INTO @Table (id,a1,a2) SELECT 1, 1, 10
INSERT INTO @Table (id,a1,a2) SELECT 1, 1, 12
INSERT INTO @Table (id,a1,a2) SELECT 2, 2, 20
INSERT INTO @Table (id,a1,a2) SELECT 2, 2, 21

SELECT  *
FROM    @Table t
WHERE   a2 = (SELECT TOP 1 a2 FROM @Table WHERE id = t.id AND a1 = t.a1)
astander
thank your answerbut not my answer maybe express not clear
shuc