English 中文(简体)
Join 2 table: allrows from the first with a sub-set from the second
原标题:Join two tables: all rows from the first with a sub-set from the second

This should be simple but no matter what I try I can t get the data I want... I have two tables:

<><>独立>

empID  relID      dob
100     1     8/8/1988
100     2     1/1/2001
200     1     9/9/1989

<>employee e

empID
100
200
300

我需要加入:

<>Desired Results(只有带有rel=1的 do)

e.empID  d.dob
100     8/8/1988
200     9/9/1989
300     NULL

不管是否与我一起使用,我最后只拿到相互交错的记录(如果受扶养的职工会有记录,有手提=1)。

www.un.org/Depts/DGACM/index_french.htm

e.empID  d.dob
100     8/8/1988
200     9/9/1989


SELECT e.empID, d.dob 
FROM employee AS e LEFT OUTER JOIN dependent AS d ON e.empID = d.empID
WHERE (d.relID = 1)

我失踪/错是什么?

感谢您的热情关注!

最佳回答

a. 使过滤器成为加入的条件:

SELECT e.empID, d.dob 
FROM employee AS e 
LEFT OUTER JOIN dependent AS d 
ON e.empID = d.empID
AND d.relID = 1
问题回答

暂无回答




相关问题
SQL Server database is not visible

I have installed ASP.NET application with database on our server. ASP.NET application created database using connection string below. The problem is that I do not see database in SQL Server Management ...

Most efficient way to store number 11.111 in SQL Server

What datatype is the most efficient to store a number such as 11.111. The numbers will have up 2 digits before the point and up to three after. Currently the column is a bigint , I am guessing that ...

表格和数据表

是否需要在提瓜表之后更新表格统计数据,还是自动更新?

Inconsistent Generate Change Script

I add a column of type tinyint and being set to not allow nulls in a table and generate the change scripts. The table has data in it at this time. The script has code that creates a temp table and ...

Performance of Sql subqueriesfunctions

I am currently working on a particularly complex use-case. Simplifying below :) First, a client record has a many-to-one relationship with a collection of services, that is, a single client may have ...

selecting one value out of an xml column

I have a particularly troublesome xml column to query data from. The schema is fixed by the Quebec Ministry of Revenue so "it is what it is" The important part of the query looks like this: with ...

Selecting records during recursive stored procedure

I ve got a content management system that contains a hierarchical structure of categories, with sub-categories subject to different ordering options at each level. Currently, that s retrieved by a (...

热门标签