English 中文(简体)
Edit: Question CHANGED -kou: Taking allrows from table wherelyn name are NOT in another table
原标题:Edit: QUESTION CHANGED - SQL: Taking all rows from table where column names are NOT in another table
  • 时间:2011-08-31 00:14:21
  •  标签:
  • sql
  • oracle

以前从未做过(这是我可能不知道的),

我有两个表格:

Table1:

Column Names:    A    B    C
Rows:            1  sdf  sdsd
                 2  seg  werr

以及

Table2:

Column Names:    A    B    C     D    E    F
Rows:            1    sdf  sdsd  yuj  uui  ddd
                 1    sdf  sdsd  sss  sdd  ssw
                 1    sdf  sdsd  jut  scv  sef
                 2    seg  werr  oel  ewe  wee
                 2    seg  werr  ujf  etr  wuk
                 2    seg  werr  los  hjd  wee

EDIT:问题发生了变化。

How do I take all rows with the columns that are unique in the 2nd table? I.e. I only want the data from D, E 以及 F where the values in A, B, C in Table1 correspond to the A, B, C values in Table2.

So for instance given A=1 以及 B=sdf, I want the rows:

sdsd  yuj  uui  ddd
sdsd  sss  sdd  ssw
sdsd  jut  scv  sef

我只能去做:从表2WHERE A= 1和B= sdf中选取,但我会收到。

1    sdf  sdsd  yuj  uui  ddd
1    sdf  sdsd  sss  sdd  ssw
1    sdf  sdsd  jut  scv  sef
最佳回答

请选择哪一栏。

例如,A= 1 B= sdf :

SELECT C,D,E,F FROM Table2 WHERE A= 1  AND B= sdf  
问题回答

The most direct way would be:

Select D, E From Table2

如果你寻找某种动态,解决办法将取决于你使用哪一个数据库供应商。 没有一个神学的动态解决办法。

希望在<代码>WHERE中特别运行的<编码> LEFT JOIN(或>>,以寻找非配对价值。

在此情况下,情况如下:

SELECT Table2.*
FROM Table2 LEFT JOIN Table1 USING (SomeCommonField)
WHERE Table1.SomeCommonField IS NULL

总的来说, 你们需要查阅系统表格或数据表来这样做。 确切的辛迪加取决于您使用什么样的房舍管理处。

看来,在座各位看来,唯一的一种情况是,由于你的名字在两个表格中都完全相同,因此,全国住户抽样调查网络就是适当的解决办法。

 SELECT D, E, F
   FROM table1
NATURAL JOIN table2
  WHERE a =  1 
    AND b =  sdf 
    AND c =  sdsd 




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

How to make a one to one left outer join?

I was wondering, is there a way to make a kind of one to one left outer join: I need a join that matches say table A with table B, for each record on table A it must search for its pair on table B, ...

Insert if not exists Oracle

I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert. Something like: INSERT ALL ...

How can I store NULLs in NOT NULL field?

I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table s ...

Type reference scope

I m studying databases and am currently working on a object-relational DB project and I ve encountered a small problem with the number of possible constraints in an object table. I m using "Database ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...