Group_concat subquery with joins from junction table

I need help with the subqueries or another answer that I may not know I need. All of the code elicits the correct results excepts for the subqueries but they do when I run them on their own. With the current code I receive an error of [21000][1241] Operand should contain 1 column(s). I tried with regular type joins without the subquery and the totals for the summed acreages was not correct. Thank you.

       nois.finished                                                       as "NOI Finished",
       enrollments.payment_date                                            as "Enrolled",
       a1.company                                                          as "Agricultural Operation Company",
       a1.street                                                           as "Agricultural Operation Street",
       a1.city                                                             as "Agricultural Operation City",
       a1.st                                                               as "Agricultural Operation St",
       a1.zip                                                              as "Agricultural Operation Zip",
       a1.phone                                                            as "Agricultural Operation Phone",
       a1.email                                                            as "Agricultural Operation Email",
       group_concat(DISTINCT p.parcel_number)                              as "Assessor Parcel Nos",
       sum(p.irrigated_acres)                                              as "Irrigated Acres",
       sum(p.non_irrigated_acres)                                          as "Non-Irrigated Acres",
       sum(p.total_acres)                                                  as "Total Acres",
       (select member_id,
               group_concat(distinct ct.name)
        from users
                 join parcels p on users.id = p.user_id
                 join parcels_2_crop_types p2ct on p.id = p2ct.parcel_id
                 join crop_types ct on p2ct.crop_type_id = ct.id
        group by member_id)                                                as "Crop Types",
       (select member_id,
               group_concat(distinct ist.name)
        from users
                 join parcels p on users.id = p.user_id
                 join parcels_2_irrigation_system_types p2ist on p.id = p2ist.parcel_id
                 join irrigation_system_types ist on p2ist.irrigation_system_type_id = ist.id
        group by member_id)                                                as "Irrigation System Types",
       group_concat(IF(p.pesticides_used = 1, 'Yes', 'No'))                as "Are pesticides used?",
       group_concat(IF(p.pesticide_regulation_permit = 1, 'Yes', 'No'))    as "Pesticide Regulation Permit",
       group_concat(DISTINCT p.operator_identification_number)             as "Operator Identification Number",
       group_concat(DISTINCT p.operator_identification_number_site_id)     as "Operator Identification Number Site ID",
       group_concat(DISTINCT p.pesticide_permit_holder)                    as "Name of Permit Holder",
       group_concat(DISTINCT p.pesticide_permit_holder_site_id)            as "Permit Holder Site ID",
       concat(a2.first_name, ' ', a2.last_name)                            as "Property Owner Name",
       a2.street                                                           as "Property Owner Street",
       a2.city                                                             as "Property Owner City",
       a2.st                                                               as "Property Owner St",
       a2.zip                                                              as "Property Owner Zip",
       a2.phone                                                            as "Property Owner Phone",
       a2.email                                                            as "Property Owner Email",
       concat(a3.first_name, ' ', a3.last_name)                            as "Agricultural Operation Owner Name",
       a3.street                                                           as "Agricultural Operation Owner Street",
       a3.city                                                             as "Agricultural Operation Owner City",
       a3.st                                                               as "Agricultural Operation Owner St",
       a3.zip                                                              as "Agricultural Operation Owner Zip",
       a3.phone                                                            as "Agricultural Operation Owner Phone",
       a3.email                                                            as "Agricultural Operation Owner Email",
       concat(a4.first_name, ' ', a4.last_name)                            as "Operator Information Name",
       a4.street                                                           as "Operator Information Street",
       a4.city                                                             as "Operator Information City",
       a4.st                                                               as "Operator Information St",
       a4.zip                                                              as "Operator Information Zip",
       a4.phone                                                            as "Operator Information Phone",
       a4.email                                                            as "Operator Information Email",
       IF(nois.groundwater_wells_used_for_drinking_water = 1, 'Yes', 'No') as "Groundwater wells used for drinking water supply",
       nois.groundwater_monitoring_by                                      as "Groundwater monitoring will be done by",
       IF(nois.has_waterbodies_located_within_100_feet = 1, 'Yes', 'No')   as "Waterbodies located within 100 feet of Agricultural Operation",
       nois.waterbodies_located_within_100_feet                            as "If yes provide name of waterbody",
       IF(nois.has_waterbody_pass_through_or_exist_on = 1, 'Yes', 'No')    as "Waterbody pass through or exist on the Agricultural Operation",
       nois.waterbody_pass_through_or_exist_on                             as "If yes provide name of waterbody",
       IF(nois.has_irrigation_return_flow_or_storm_water_discharged = 1, 'Yes',
          'No')                                                            as "Irrigation return flow or storm water discharged directly to a waterbody"
FROM users
         join parcels p
              on users.id = p.user_id
         join nois
              ON users.id = nois.user_id
         left join enrollments
                   on users.member_id = enrollments.member_number
         left join addresses a1
                   ON nois.agricultural_operation_address_id = a1.id
         left join addresses a2
                   on nois.property_owner_address_id = a2.id
         left join addresses a3
                   ON nois.agricultural_operation_owner_address_id = a3.id
         left join addresses a4
                   on nois.operator_address_id = a4.id
where p.active = 1
group by member_id;```

         



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)