Greeting to the Community and prop's to the SugarCRM developers.
I hope I'm in the correct forum.
I am trying to build a query that will pull "name" of "account_type" from the `accounts` table and match it to the "description" field from `notes`. I can achieve the results I need with separate query's but need to condense into one query.
//Potential AVD
SELECT a.`name`, n.`description`, n.`date_modified`
FROM accounts a
JOIN notes n
ON a.id = n.parent_id
JOIN users u
ON u.id = a.assigned_user_id
WHERE a.`account_type`="Potential AVD"
//AVD
SELECT a.`name`, n.`description`, n.`date_modified`
FROM accounts a
JOIN notes n
ON a.id = n.parent_id
JOIN users u
ON u.id = a.assigned_user_id
WHERE a.`account_type`="AVD"
//A&E
SELECT a.`name`, n.`description`, n.`date_modified`
FROM accounts a
JOIN notes n
ON a.id = n.parent_id
JOIN users u
ON u.id = a.assigned_user_id
WHERE a.`account_type`="A&E"
//Platinum Dealer
SELECT a.`name`, n.`description`, n.`date_modified`
FROM accounts a
JOIN notes n
ON a.id = n.parent_id
JOIN users u
ON u.id = a.assigned_user_id
WHERE a.`account_type`="Platinum Dealer"
//National Account
SELECT a.`name`, n.`description`, n.`date_modified`
FROM accounts a
JOIN notes n
ON a.id = n.parent_id
JOIN users u
ON u.id = a.assigned_user_id
WHERE a.`account_type`="National Account"
//End User Account
SELECT a.`name`, n.`description`, n.`date_modified`
FROM accounts a
JOIN notes n
ON a.id = n.parent_id
JOIN users u
ON u.id = a.assigned_user_id
WHERE a.`account_type`="End User Account"
//Opportunitie Notes:
SELECT o.`name`, n.`description`, n.`date_modified`
FROM opportunities o
JOIN notes n
ON o.id = n.parent_id
JOIN users u
ON u.id = o.assigned_user_id


LinkBack URL
About LinkBacks



Reply With Quote
Bookmarks