I have two tables one is schools and one is students.I want to find all the students of a particular school. The schema of schools is: id, name, location and of students is
Use collect_set()
with concat_ws
to get comma delimited string, IDs should be cast to string:
schoolId=$(hive -e "set hive.cli.print.header=false;select concat_ws('\\',\\'',collect_set(cast(id as string))) from school;");
hive -hiveconf "schoolId"="$schoolId"
Then use IN operator:
select id,name from student where schoolId in ('${hiveconf:schoolId}');