| От | Gerhard Dieringer |
|---|---|
| Тема | Antw: Problems with joining two tables |
| Дата | |
| Msg-id | s8fec883.010@kopo001 обсуждение исходный текст |
| Список | pgsql-sql |
Michael Rudolph wrote: > I have two tables, the first one has one column as a reference to the index of the second. Not every row in the first tablehas a reference to the second table. > I now want to make a query to get all information of the first table and, ifthere is a reference, the corresponding information of the second table in that row. In > another programming languageI would just make an if-clause but how can I do this in SQL? What you need is an outer join but as PostgreSQL doesn't support outer joins now (7.0.0), you can simulate it with a unionas explained in Bruce Momjian book: SELECT name, order_id FROM customer, salesorder WHERE customer.customer_id = salesorder.customer_id UNION ALL SELECT name, NULL FROM customer WHERE customer.customer_id NOT IN (SELECT customer_id FROM salesorder) ORDER BY name I hope this will help you. Gerhard
В списке pgsql-sql по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера