Re: Hint for a query

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: Hint for a query
Дата
Msg-id BB292D59-CF88-4301-AC61-CCD66E2C9129@yahoo.com
обсуждение исходный текст
Ответ на Hint for a query  (Efrain Lopez <tecnomaya@cabsagt.com>)
Список pgsql-general
On Nov 4, 2011, at 0:37, Efrain Lopez <tecnomaya@cabsagt.com> wrote:

> I have this tables
>
>
> Table: Contact
> IdContact
> First Name
> Second Name
> … other columns
>
> Table: Employee
> IdEmployee
> IdContact, related to Contact table
> … other columns
>
> Table: Salesman
> IdSaleman
> IdEmployee, if salesman is employee, related to Employee table
> IdContact, if salesman is not an employee, related to Contact table
>
>
> I need a query
>
> Id Salesman - Second name - First name
>
> But I can't figure how to do it, can someone can give advise?
>
> Thanks
>
>

SELECT + JOIN

The query you seek seems too simple that either you have not learned how to do simple SELECTS with multiple tables OR
youare not clear regarding what is confusing you. 

The documentation and other books/articles on basic SQL will help in the first case.  Showing what work you have tried
upto this point will help with the second. 

Your tables also will be cumbersome to use as designed, but your immediate question is easily answered with the
existingschema.  In short the link to contact from salesperson is questionable since employee already links there.
Thereis not enough context to provide alternatives but it is worth looking into. 

David J.

В списке pgsql-general по дате отправления:

Предыдущее
От: Efrain Lopez
Дата:
Сообщение: Hint for a query
Следующее
От: Stuart Bishop
Дата:
Сообщение: Excessive planner time for some queries with high statistics