Link to home
Start Free TrialLog in
Avatar of lfwebz
lfwebz

asked on

how to set up query to pull Magento customer information

I had most of this query worked out, or so I thought, except for two things, large things, one, as soon as I add the forth table [departments_tbl]into the query, I get about 800 rows returned when I should only have about 100.

See the attached schema, note the checkmarks, these are the fields I want returned.
In a nutshell I want email, first/last name, billing_state, store_name, lastlogin, customer_grp_code, manager and manager_email [I have checked a few other in the image, but these are the main ones].  Also please note that entity_id and cust_id fields would the be links between the _ncust_rpt_copy table and the _n_cust_entity_storeid_15 tbl

This won't help, but here is just one of the queries that I almost had working, until the [department_tbl was added to the mix]
SELECT _n_cust_entity_storeid_15.entity_id, 
    _n_cust_entity_storeid_15.email, 
    customer_group.customer_group_code, 
    departments.`name`, 
    departments.manager, 
    _n_cust_rpt_copy.first_name, 
    _n_cust_rpt_copy.last_name, 
    _n_cust_rpt_copy.last_login_date, 
    _n_cust_rpt_copy.billing_address, 
    _n_cust_rpt_copy.billing_city, 
    _n_cust_rpt_copy.billing_state, 
    _n_cust_rpt_copy.billing_zip
FROM _n_cust_entity_storeid_15 INNER JOIN customer_group ON _n_cust_entity_storeid_15.group_id = customer_group.customer_group_id
     INNER JOIN departments ON _n_cust_entity_storeid_15.store_id = departments.store_id, 
    _n_cust_rpt_copy
ORDER BY _n_cust_rpt_copy.last_name ASC

Open in new window


I've tried subqueries, joins, but just can't get it to work.

Any help would be greatly appreciated.
User generated image
Avatar of lfwebz
lfwebz

ASKER

I think I am closing in on this one, but ran into another snag and have no idea how to fix it

What is wrong with this query - just get the generic "you have an error", it is point to the join, but I don't know how to fix it.

select c.*,
(select caet.value from customer_address_entity_test caet where cae.entity_id = caet.value_id and
caet.attribute_id = 23) as test,
(select çaev.value from customer_address_entity_varchar caev where caet.entity_id = caev.entity_id and caev.attribute_id = 23) two
join customer_address_entity cae on c.`entity_id` = cae.`parent_id`
from customer_entity c where store_id = 8
ASKER CERTIFIED SOLUTION
Avatar of David Todd
David Todd
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh: @David, regret to say I disagree on join syntax convention

LEFT JOIN thistable ON priortable.id = thistable.id

I always recommend listing the priortable first
helps keep 'left' relevant too IMHO