MySQL在连接中只能使用61个表;如何绕过此错误以进行以下查询?

时间:2016-06-10 10:05:29

标签: mysql sql database

我收到MySQL错误说,我在连接中不能使用超过61个表。我需要避免这个错误。我该怎么做?请帮助。

select
    view_pdg_institutes.user_id as User_ID,
    view_pdg_institutes.institute_id as Teacher_ID,
    view_pdg_institutes.institute_name as Institute_Name,
    view_pdg_institutes.user_email as Email,
    view_pdg_institutes.contact_person_name as Contact_Person,
    view_pdg_institutes.alternative_contact_no as Alternative_Mobile_No,
    view_pdg_institutes.primary_contact_no as Mobile_No,
    view_pdg_institutes.correspondance_address as Address,
    view_pdg_institutes.other_communication_mode as Preferred_Contact_Mode,
    view_pdg_institutes.size_of_faculty as Size_of_Faculty,
    view_pdg_institutes.operation_hours_from as Operation_Hours_From,
    view_pdg_institutes.operation_hours_to as Operation_Hours_To,
    view_pdg_institutes.teaching_xp as Teaching_Experience,
    view_pdg_institutes.installment_allowed as Installment_Allowed,
    view_pdg_institutes.about_fees_structure as About_Fees_Structure,
    view_pdg_institutes.no_of_demo_class as No_of_Demo_Classes,
    view_pdg_institutes.demo_allowed as Demo_Allowed,
    view_pdg_institutes.price_per_demo_class as Price_Per_Demo_Class,
    view_pdg_tuition_batch.tuition_batch_id as Batch_ID,
    view_pdg_batch_subject.subject_name as Subject_Name,
    view_pdg_batch_subject.subject_type as Subject_Type,
    view_pdg_batch_subject.academic_board as Academic_Board,
    view_pdg_batch_fees.fees_type as Fees_Type,
    view_pdg_batch_fees.fees_amount as Fees_Amount,
    view_pdg_tuition_batch.course_days as Course_Days,
    view_pdg_tuition_batch.days_per_week as Days_Per_Week,
    view_pdg_tuition_batch.class_duration as Class_Duration,
    view_pdg_tuition_batch.class_type as Class_Type,
    view_pdg_tuition_batch.course_length as Course_Length,
    view_pdg_tuition_batch.course_length_type as Course_Length_Type,
    view_pdg_tuition_batch.no_of_locations as No_of_Locations,
    view_pdg_tuition_batch.class_capacity_id as Class_Capacity_ID,
    view_pdg_tutor_location.locality as Locality,
    view_pdg_tutor_location.address as Address,
    view_pdg_batch_class_timing.class_timing as Class_Timing

    from view_pdg_tuition_batch

    left join view_pdg_institutes on (view_pdg_tuition_batch.tutor_institute_user_id = view_pdg_institutes.user_id)
    left join view_pdg_batch_subject on (view_pdg_batch_subject.tuition_batch_id = view_pdg_tuition_batch.tuition_batch_id)
    left join view_pdg_batch_fees on (view_pdg_batch_fees.tuition_batch_id = view_pdg_tuition_batch.tuition_batch_id) 
    left join view_pdg_batch_class_timing on (view_pdg_batch_class_timing.tuition_batch_id = view_pdg_tuition_batch.tuition_batch_id)
    left join view_pdg_tutor_location on (view_pdg_tutor_location.tuition_batch_id = view_pdg_tuition_batch.tuition_batch_id)
group by view_pdg_tuition_batch.tuition_batch_id;

我需要一个不需要改变当前编写查询方法的解决方案。

2 个答案:

答案 0 :(得分:0)

将每个视图的内容插入到自己的临时表中。然后使用替换原始视图名称的临时表名执行相同的查询。

答案 1 :(得分:0)

我认为,如果不对存储和查询数据的方式进行一些细致的更改,就可以做你要求的事情。你可以

  1. 对数据库进行非规范化以存储JSON数据;
  2. 创建物化视图,通过触发器模拟它们,因为它们在MySQL中不存在;
  3. 使用临时表;
  4. 在呼叫站点手动加入部分选择;
  5. 使用另一个连接限制编译MySQL;
  6. 使用适当的SQL引擎,如Postgres,doesn't suffer来自这些愚蠢的事情。