で複数のテーブルから選択します:knex.jsとknex.jsこのクエリを実行する方法
select * from table1, table2;
?
私はこれを試してみた:
const knex = require('knex')({
client: 'sqlite3',
connection: { filename: ':memory:' },
})
async function main() {
await knex.schema.createTable('table1', table => table.string('field1'))
await knex.schema.createTable('table2', table => table.string('field2'))
await knex.insert({ field1: 'value' }).into('table1')
await knex.insert({ field2: 'value' }).into('table2')
await knex.from('table1', 'table2') // first attempt
await knex.from(['table1', 'table2']) // second attempt
}
main().catch(err => {
console.error(err)
})
私はENV DEBUG='knex:query'
でそのコードを実行し、この出力を得た:
create table `table1` (`field1` varchar(255))
create table `table2` (`field2` varchar(255))
insert into `table1` (`field1`) values (?)
insert into `table2` (`field2`) values (?)
select * from `table1`
select * from `table1` as `0`, `table2` as `1`
は明らかに、select
文は私が期待したものではありません。
PS:あなたはこの質問をマークした場合の
はそうではない、this oneの複製です。 質問の主な点が異なり、回答はthat question で私の質問には答えません。
select * from table1, table2;
select * from table1 cross join table2;