简体   繁体   English

与两个表之间没有共同关系的表B列值相比,从表A中检索列

[英]Retrieve columns from table A in comparsion to table B column values where there is no common relationship between two tables

A new bird to SQL. SQL的新鸟。

Table A name is EmployeeDetails which has four columns. 表名称是EmployeeDetails,它有四列。

EmployeeID  FirstName,  LastName,  NativeState
        1     Frank        Dyre         FL
        2     John         Smith        AL
        3     Taylor       Cox          GA

Table B is CompanyDetails which has three columns 表B是CompanyDetails,其中包含三列

CompanyID   CompanyName  HeadQuatersState
 1           Steve's       FL
 2           Johnson       NY
 3           Huston        GA

Now in both the tables there is no same columns. 现在,两个表中没有相同的列。 But Native State and HeadQuatersStat have common states. 但是Native State和HeadQuatersStat具有共同的状态。

how can I retrieve first and lastname of an employee from employeeDetails table where the nativestate is not equals to company headquarters state. 如何从employeeDetails表中检索员工的姓氏和名字,其中原始状态不等于公司总部状态。

Expected result is John Smith. 预期结果是约翰·史密斯。

I think this is what your looking for 我想这就是你要找的

SELECT EmployeeID,FirstName + ' ' + LastName 'Employee'
FROM EmployeeDetails
WHERE NativeState NOT IN (SELECT HeadQuartersState
                            FROM CompanyDetails)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 两个共有2列的SQL表需要在表A中但不在表B中的记录(列1相同,但列2不同) - two SQL tables with 2 columns in common, need records that are in table A but not in table B (column 1 is same in both but different column 2) mysql表中两列之间的公共值 - Common values between two columns in mysql table 如何使用另一个表 B 中的值更新表 A 中的列,其中表 A 和 B 之间的关系为 1:N,使用 max() 函数 - How to update a column in a table A using the value from another table B wherein the relationship between tables A & B is 1:N by using max() function 如果表A中的列A与表B中的列B相等,则从两个表(表A和b)中获取输出 - get output from two tables(table A and b) if column A from table A is equal to column B from Table B 多个表和一个公用表之间的关系 - Relationship between multiple tables and a common table 需要从不满足以下条件的表中检索行A列= B列和B列= A列 - Need to retrieve rows from table where the following condition was not satisfied column A = column B and column B = column A 如何获得 PostgreSQL 中的两个平均值之间的差异,其中平均值在一列上,而最终表格按两列分组? - How to get difference between two average values in PostgreSQL, where the averages are on a column, and the final table grouped by two columns? SQL查询联接一列的平均值,其中另一列在另一表的两列值之间 - Sql query join average of one column where another column is between two columns values of another table 在表的其他列中的值相同的列的两个值之间进行选择 - Choose between two values of a column where the values in other columns of the table are same 如何通过一个表中的一列从关系中的两个表中获取值 - How to get values from two tables in relationship thru one column in one table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM