ios - INNER JOIN 查询不起作用
<p><p>我在两个名为 EMPLOYEE 和 DEPARTMENT 的表上使用 INNERJOIN 查询。
存在一个常见的 empID(1234),它在两个表中都很常见,我想使用连接查询从两个表中获取数据。但它不工作。下面是我的代码:</p>
<pre><code>NSString *querySQL = [NSString stringWithFormat:
@"Select EMPLOYEE.* from EMPLOYEE INNER JOINDEPARTMENT ONEMPLOYEE.empID = DEPARTMENT.empID =%@",_txtfind.text];
NSLog(@"fetch query is%@",querySQL);
const char *query_stmt = ;
if (sqlite3_prepare_v2(database,
query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
if(sqlite3_step(statement) == SQLITE_ROW)
{
NSString *name = [ initWithUTF8String:
(const char *) sqlite3_column_text(statement, 0)];
;
NSString *department = [ initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)];
;
NSString *year = [initWithUTF8String:
(const char *) sqlite3_column_text(statement, 2)];
;
NSLog(@"result array is %@",resultArray);
}
else{
NSLog(@"Not found");
}
sqlite3_reset(statement);
}
</code></pre>
<p>它总是转到其他部分并显示“未找到”。
难道我做错了什么?我的加入查询是否正确?我是新加入概念所以请帮助我,你的想法是完全欢迎的。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这是您的查询,我理解到 <code>on</code> 子句结束:</p>
<pre><code>Select EMPLOYEE.*
from EMPLOYEE INNER JOIN
DEPARTMENT
ON EMPLOYEE.empID = DEPARTMENT.empID =%@",_txtfind.text];
</code></pre>
<p>也许你想要某种 <code>where</code> 子句?</p>
<pre><code>Select e.*, d.col1, d.col2, . . .
from EMPLOYEE e INNER JOIN
DEPARTMENT d
ON e.empID = d.empID
where e.empId = 'txtfind.text';-- something like this
</code></pre>
<p>无论如何,如果这没有帮助,请编辑您的问题并在变量替换后显示 SQL 查询。</p></p>
<p style="font-size: 20px;">关于ios - INNER JOIN 查询不起作用,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/30836461/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/30836461/
</a>
</p>
页:
[1]