Re: [SQL] self join

2011-05-14 Thread Jasen Betts
On 2011-05-14, Seb wrote: > Hi, > > This probably reflects my confusion with how self joins work. > > Suppose we have this table: > If I want to get a table with records where none of the values in column > b are found in column a, I thought this should do it: use the "NOT IN" operator with a su

Re: [SQL] self join

2011-05-14 Thread Seb
On Sun, 15 May 2011 07:39:06 +0900, Ian Lawrence Barwick wrote: [...] > Your query doesn't have an explicit join and is producing a cartesian > result. > I don't think a self- join will work here; a subquery should produce > the result you're after: > SELECT * FROM tmp t1 WHERE NOT EXISTS(SELE

Re: [SQL] self join

2011-05-14 Thread Ian Lawrence Barwick
Hi 2011/5/15 Seb : > Hi, > > This probably reflects my confusion with how self joins work. > > Suppose we have this table: > > =# SELECT * FROM tmp; >  a | b > ---+--- >  1 | 2 >  2 | 3 >  4 | 5 > (3 rows) > > If I want to get a table with records where none of the values in column > b are found i

[SQL] self join

2011-05-14 Thread Seb
Hi, This probably reflects my confusion with how self joins work. Suppose we have this table: =# SELECT * FROM tmp; a | b ---+--- 1 | 2 2 | 3 4 | 5 (3 rows) If I want to get a table with records where none of the values in column b are found in column a, I thought this should do it: =# SE

[SQL] Re: [SQL] Sorting data based fields in two linked tables

2011-05-14 Thread Charlie
SELECT A.ID,A.FIELD1,A.FIELD2,  B.FIELD1,B.FIELD2, B.FIELD1,B.FIELD2, B.FIELD1,B.FIELD2 FROM a INNER JOIN B ON a.id = b.a_id ORDER BY a.field2 ASC, b.field1 ASC ; - Reply message - From: "R. Smith" Date: Fri, May 13, 2011 12:00 pm Subject: [SQL] Sorting data based fields in two linked

Re: [SQL] Sorting data based fields in two linked tables

2011-05-14 Thread Oliver d'Azevedo Christina
Can you provide An example? Best, Oliveiros Enviado via iPhone Em 13/05/2011, às 04:00 PM, "R. Smith" escreveu: > Hi, > > I am looking for a way to sort data returned from two tables with the > first sort based on a field from table A and the secord sort based on > the results of the first so

[SQL] Sorting data based fields in two linked tables

2011-05-14 Thread R. Smith
Hi, I am looking for a way to sort data returned from two tables with the first sort based on a field from table A and the secord sort based on the results of the first sort but the sort field is from table B. While I can sort on either fields from either table, I cannot get it to work on both. I