Re: [GENERAL] Using AND in query

2010-08-08 Thread David Fetter
On Sun, Aug 08, 2010 at 12:33:40PM -0700, David Fetter wrote: > On Sun, Aug 08, 2010 at 01:55:19AM -0700, John R Pierce wrote: > > >The condition > > > > > > and table.item = 'laptop' and table.item = 'Desktop' > > > > > >says: I want all rows where the column item has the value > > >'Laptop' and

Re: [GENERAL] Using AND in query

2010-08-08 Thread David Fetter
On Sun, Aug 08, 2010 at 01:55:19AM -0700, John R Pierce wrote: > >The condition > > > > and table.item = 'laptop' and table.item = 'Desktop' > > > >says: I want all rows where the column item has the value 'Laptop' > >and *at the same time* has the value 'Desktop' > >Which clearly cannot be the c

Re: [GENERAL] Using AND in query

2010-08-08 Thread Thomas Kellerer
Alban Hertroys wrote on 08.08.2010 10:46: On 7 Aug 2010, at 23:18, Thomas Kellerer wrote: Or as an alternative: SELECT tid, purchase_date FROM orders WHERE item in ('Laptop', 'Desktop') GROUP BY tid, purchase_date HAVING count(*) = 2 This one is incorrect, it will also find people who bough

Re: [GENERAL] Using AND in query

2010-08-08 Thread John R Pierce
The condition and table.item = 'laptop' and table.item = 'Desktop' says: I want all rows where the column item has the value 'Laptop' and *at the same time* has the value 'Desktop' Which clearly cannot be the case (a column can only have a single value) So you need to join all "Laptop"

Re: [GENERAL] Using AND in query

2010-08-08 Thread Alban Hertroys
On 7 Aug 2010, at 23:18, Thomas Kellerer wrote: > Or as an alternative: > > SELECT tid, purchase_date > FROM orders > WHERE item in ('Laptop', 'Desktop') > GROUP BY tid, purchase_date > HAVING count(*) = 2 This one is incorrect, it will also find people who bought two laptops or two desktops o

Re: [GENERAL] Using AND in query

2010-08-07 Thread David Fetter
On Sat, Aug 07, 2010 at 12:40:41PM -0700, aravind chandu wrote: > Hello every one, > > I have encountered a problem while working .I have a sample table with the > following data > > > TID Date Item > T100 8/1/2010 Laptop > T100 8/1/2010 Desktop > T101 8/1/2010 Laptop > T102 8/1/2010 Deskt

Re: [GENERAL] Using AND in query

2010-08-07 Thread Thomas Kellerer
aravind chandu wrote on 07.08.2010 21:40: Hello every one, I have encountered a problem while working .I have a sample table with the following data *TID* *Date* *Item* T1008/1/2010Laptop T1008/1/2010Desktop T1018/1/2010Laptop T1028/1/2010Desktop

Re: [GENERAL] Using AND in query

2010-08-07 Thread Raymond O'Donnell
On 07/08/2010 20:40, aravind chandu wrote: condition in where clause : table.date in date() to date() and table.item = "laptop" and table.item = "Desktop" I don't think this is correct - you need "BETWEEN". Ray. -- Raymond O'Donnell :: Galway :: Ireland r...@iol.ie -- Sent via pgsql-general