2013-10-14 37 views
0

我從兩個表中選擇數據在正常情況下,它工作正常,但如果我使用where子句它不會返回任何東西。如何從iPhone中的數據從sqlite表中使用在哪裏Cluase我

這裏是查詢

NSString *select =[NSString stringWithFormat:@"SELECT *from ContentMaster As ml LEFT JOIN ContentTagging As cat ON cat.ContentID = ml.ContentID where cat.ContenTagText= %@" , appDelegate.tagInput]; 

這裏是查詢的NSLog

SELECT *from ContentMaster As ml LEFT JOIN ContentTagging ON cat.ContentID = ml.ContentID where cat.ContenTagText= Tag1 
+0

你在sqllite中執行此查詢嗎?它有什麼價值?如果是,則檢查appDelegate.tagInput是否有一些值。打印選擇查詢,並檢查它的糾正 – KDeogharkar

+0

是的,我打印appDelegate.tagInput它有價值和QUERY結果也顯示這裏是結果SELECT * from ContentMaster作爲ml LEFT JOIN ContentTagging ON cat.ContentID = ml.ContentID在哪裏貓.ContenTagText = Tag1 –

回答

1

把你ContenTagText在'',因爲它是比較字符串

NSString *select =[NSString stringWithFormat:@"SELECT * from ContentMaster As ml LEFT JOIN ContentTagging As cat ON cat.ContentID = ml.ContentID where cat.ContenTagText= \'%@\'" , appDelegate.tagInput]; 

查詢將被:

SELECT *from ContentMaster As ml LEFT JOIN ContentTagging ON cat.ContentID = ml.ContentID where cat.ContenTagText= 'Tag1' 

希望能對您有所幫助。

+0

感謝它爲我工作 –

+0

任何想法,如果我想也從ContentTagging獲得ContentTagText然後如何添加,在這 –

+0

你可以嘗試與「ContentTagging作爲ct,ContentMaster的ContentTagging作爲內容文本的SELECT *,ct。ContentTagText作爲ml ....「 – KDeogharkar

相關問題