Обсуждение: Query Help

Поиск
Список
Период
Сортировка

Query Help

От
"Brian C. Doyle"
Дата:
What do I have to do a query where information in table1 is not in table2

I am looking for something like

Select table1.firstname where table1.firstname is not in table2.firstname 
and table2.date='yesterday'

I tried
Select table1.firstname where table1.firstname != table2.firstname and 
table2.date='yesterday'

and that did not work just listed everyone....





RE: Query Help

От
"Francis Solomon"
Дата:
Hi Brian,

Try something like this:

SELECT firstname FROM table1 WHERE firstname NOT IN (SELECT firstname
FROM table2 WHERE table2.date='yesterday'::date);

Hope this helps.

Francis Solomon

>
> What do I have to do a query where information in table1 is
> not in table2
>
> I am looking for something like
>
> Select table1.firstname where table1.firstname is not in
> table2.firstname
> and table2.date='yesterday'
>
> I tried
> Select table1.firstname where table1.firstname !=
> table2.firstname and
> table2.date='yesterday'
>
> and that did not work just listed everyone....



Re: Query Help

От
Yury Don
Дата:
Hello Brian,

Wednesday, December 27, 2000, 9:20:53 PM, you wrote:

BCD> What do I have to do a query where information in table1 is not in table2

BCD> I am looking for something like

BCD> Select table1.firstname where table1.firstname is not in table2.firstname 
BCD> and table2.date='yesterday'

BCD> I tried
BCD> Select table1.firstname where table1.firstname != table2.firstname and 
BCD> table2.date='yesterday'

BCD> and that did not work just listed everyone....

If I understand correctly
Select table1.firstname from table1 where not exists
(select table2.firstname from table2 where table1.firstname = table2.firstname and
table2.date='yesterday')


-- 
Best regards,Yury                            mailto:yura@vpcit.ru




Re: Query Help

От
patrick.jacquot@anpe.fr
Дата:
"Brian C. Doyle" wrote:

> What do I have to do a query where information in table1 is not in table2
>
> I am looking for something like
>
> Select table1.firstname where table1.firstname is not in table2.firstname
> and table2.date='yesterday'
>
> I tried
> Select table1.firstname where table1.firstname != table2.firstname and
> table2.date='yesterday'
>
> and that did not work just listed everyone....

imho the most natrural way for what you need seems to be :

select  whatyouwant from table1 where not exists   select * from table2 where table2.firstname = table1.firstname and
table2.date='yesterday';

hoping that helps
P. Jacquot



Re: Query Help

От
"Brian C. Doyle"
Дата:
Thank you to everyone with their suggestions.....

Where on the PostgreSQL site would I have found more info on the NOT EXISTS

At 11:20 AM 12/27/00 -0500, you wrote:
>What do I have to do a query where information in table1 is not in table2
>
>I am looking for something like
>
>Select table1.firstname where table1.firstname is not in table2.firstname 
>and table2.date='yesterday'
>
>I tried
>Select table1.firstname where table1.firstname != table2.firstname and 
>table2.date='yesterday'
>
>and that did not work just listed everyone....
>