2

確かに簡単な質問ですが、MySQL クエリを修正できません: 準備されたクエリの下で実行したい

select id from table1 where c_id = :c_id 
union 
select id,name from table2 where c_id = :c_id and temp = :temp

したがって、各テーブル選択の出力には異なる数の列があります。これが機能しない理由ですか?

4

1 に答える 1

2

SELECT次のように、最初のクエリでリテラル値を使用できます。

SELECT id, 'no name' AS "name" FROM table1 WHERE c_id = :c_id
UNION ALL
SELECT id, name                FROM table2 WHERE c_id = :c_id 
                                             AND temp = :temp;
于 2012-12-19T11:57:32.237 に答える