English 中文(简体)
SQL 查询帮助
原标题:SQL Query HELP - Nested I think
  • 时间:2012-05-23 03:16:56
  •  标签:
  • sql
  • nested

我写SQL声明,需要:

  1. Look for a job with a certain number
  2. Match that job to another table
  3. Show the results

这是我目前拥有的。

select * from PreviousJobs pj, Jobs j where jobId =  273121  
AND where (pj.sOtherRef = j.sOtherRef) = True    

毫米毫米

最佳回答

不需要筑巢;这是需要的简单联合行动,最好用明确的连号符号写:

SELECT cj.*, pj.* 
  FROM PreviousJobs AS pj
  JOIN Jobs         AS cj ON pj.sOtherRef = cj.sOtherRef
 WHERE cj.jobId =  273121  

您不需要您的语句中的第二处( 语法错误, 您本应该向我们提供您 DBMS 所给你的错误信息) 。 您不需要比较 TRUE 。

在SQL-86和SQL-89中,条款中以逗号分隔的表格名称列表是必要的,但自SQL-92支持被添加到 DBMS 中以来就没有必要了。你应该知道这一点,这样如果你读到旧的 SQL,你知道这意味着什么。但是,你应该计划只使用新的 JOIN 符号,除非工作场所标准对使用旧的符号施加巨大的(和不明智的)压力。

取决于您使用的 DBMS 格式,您可能会发现表格中的AS 名是不允许的( Oracle), 尽管标准上说可以。 区别在于为什么将您的 DBMS 信息包含在问题中是一个好主意 。

问题回答

你不需要True或者第二个地方

只是

select * from PreviousJobs pj, Jobs j where jobId =  273121  
AND pj.sOtherRef = j.sOtherRef 
  1. Look for a job with a certain number : where jobId = 273121
  2. Match that job to another table : inner join on pj.sOtherRef = j.sOtherRef
  3. Show the results : select * from PreviousJobs pj

查询将会是..

select *
  from PreviousJobs pj inner join Jobs j ON pj.sOtherRef = j.sOtherRef
 where j.jobId =  273121 




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

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 ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签