Hey everyone,
I'm trying to do some SQL programming and I'm just hitting a brick wall... I'm trying to just use SQL views to integrate better with Sugar CRM which will display the data... Here's the low down:
spar_summary_test
all_spars
all_spark
spar_summary_test and all_spars correspond perfectly with the data on them (If there is an entry on one, it's on both)
all_spark is the SQL view of my audit table containing before and after values, what I'm trying to do is pull data from all_spark IF one of the fields was set to lost if not I don't want it to join them...
I'm not sure if my problem is in my 3 inner joins, or in the SQL view I'm using to pull the third table records...
Here is my all_spark view:
SELECT parent_id as `parent_id`, before_value_string as 'lost_spar_stage_c', after_value_string from opportunities_audit where after_value_string = "Lost"
Here is my spar_summary_test view:
SELECT
all_spars_test.id,
all_spars_test.`name`,
all_spars_test.spar_active_c,
all_spars_test.ctx_school_type_c,
spar_assigned_to.user_name AS `Assigned To`,
all_spars_test.sales_region_c,
all_spars_test.sales_state_c,
all_spars_test.inst_closedt_mo_c,
all_spars_test.inst_closedt_yr_c,
all_spars_test.amount,
all_spars_test.probability,
all_spars_test.adjusted_value_c,
all_spars_test.sales_stage_c,
all_spars_test.po_closedt_mo_c,
all_spars_test.po_closedt_yr_c,
all_spars_test.po_received_c,
all_spars_test.bd_involved_c,
all_spars_test.forecasted_margin_c,
all_spars_test.user_id_c,
all_spars_test.date_entered,
all_spars_test.date_modified,
spar_modified_by.user_name AS `Modified By`,
all_spark.lost_spar_stage_c,
all_spars_test.lost_spar_reason_c
FROM all_spars_test
INNER JOIN spar_assigned_to ON all_spars_test.id = spar_assigned_to.id
INNER JOIN spar_modified_by ON all_spars_test.id = spar_modified_by.id
join all_spark on all_spars_test.id = all_spark.parent_id
WITH CASCADED CHECK OPTION
I'm not getting any errors with it, but I'm going from 1700 records to about 390 so I'm thinking that my join is causing it to display ONLY the records that match all the views.
Any ideas? Am I missing the forrest through the trees?