2017-06-06 106 views
0

查詢:是否可以使用CodeIgniter的查詢生成器進行此查詢?

select (exists (select 1 from table1 where url = 'fajne-to-jest')) as in_table1, 
     (exists (select 1 from table2 where url = 'fajne-to-jest')) as in_table2; 

我不喜歡看到存在的功能。

我不認爲這是可能的,但也許我錯了。

所以問題是,是否有可能創建這個複雜的查詢只有CodeIgniter的查詢生成器?

回答

2

可能不如您的示例那樣優化。最簡單的解決方案是不使用Querybuilder並直接在query()中使用該語句。

$sql = "select (exists (select 1 from table1 where url = 'fajne-to-jest')) as in_table1, 
       (exists (select 1 from table2 where url = 'fajne-to-jest')) as in_table2"; 
$query = $this->db->query($sql); 

Querybuilder(QB)是一個很棒的工具,但它經常(也許更常見)是完全沒有必要的。 QB的主要任務是構建查詢語句。爲什麼要執行大量代碼來創建簡單的書寫查詢?

QB非常適用於需要有條件地更改查詢語句的情況。例如,添加where子句,更改排序順序等。

+0

同意,任何複雜的查詢和連接都使用直接查詢方法。 – timothymarois

相關問題