user2710786
user2710786

Reputation: 41

Knex js How to apply union on 2 tables which has different number of columns

I have 2 tables with diff columns as shown below


Name, Age, Gender, email_id


course, course_type, university

SELECT NAME, EMAIL_ID, NULL AS COURSE, NULL AS UNIVERSITY FROM TABLEA UNION SELECT NULL AS NAME, NULL AS EMAILID, COURSE, UNIVERSITY FROM TABLEB

Upvotes: 1

Views: 559

Answers (1)

user2710786
user2710786

Reputation: 41

I tried below mentioned knex js query but getting error

  • Knexjs query

myDB .select('NAME', 'EMAIL_ID', {'NULL':'COURSE'}, {'NULL':'UNIVERSITY'}) .from('TABLEA') .union(canonDB.select({'NULL':'NAME'},{'NULL':'EMAILID'}, COURSE',UNIVERSITY}).from('TABLEB'))

  • Error :

Unknown column 'NULL' in 'field list'

Upvotes: 1

Related Questions