Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8279109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:13:39+00:00 2026-06-08T09:13:39+00:00

I am trying to group by a substring. I only get the one result:

  • 0

I am trying to group by a substring. I only get the one result:

Region = Coastal, Value (R) = 1144900.

I am supposed to get 2 results.

This is my code:

SELECT
  DISTINCT SUBSTRING_INDEX(`team_name`, '-', 1) AS 'Region', 
  SUM(`opportunities`.`value`) AS 'Value (R)'
FROM 
  `opportunities` 
  LEFT JOIN cf_type_link_data ON cf_type_link_data.sourceid = opportunities.id
  LEFT JOIN cf_lu_type_fields ON cf_type_link_data.fieldid = cf_lu_type_fields.id
  LEFT JOIN cf_lu_types_fields_dropdown ON cf_type_link_data.`value` = cf_lu_types_fields_dropdown.id AND cf_lu_type_fields.id = cf_lu_types_fields_dropdown.fieldid
  LEFT JOIN `lu_teams` ON `lu_teams`.`contactid` = `opportunities`.`user_allocation`
  LEFT JOIN `teams` ON `teams`.`id` = `lu_teams`.`teamid`
  LEFT JOIN `lu_opportunity_status` ON `lu_opportunity_status`.`id` = `opportunities`.`status`
WHERE 1 
  AND `cf_lu_types_fields_dropdown`.`values` = 'Building Project'
  AND cf_lu_type_fields.fieldname = 'Scaffolding Segment'
  AND (`opportunities`.`expecteddate` >= '2012-01-01' AND `opportunities`.`expecteddate` <= '2012-07-24')
GROUP BY 'Region' 
ORDER BY cf_lu_types_fields_dropdown.`values`;

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:13:42+00:00Added an answer on June 8, 2026 at 9:13 am

    You can not use same alias from select in GROUP BY clause

    try

    SELECT DISTINCT SUBSTRING_INDEX(team_name, '-', 1) AS 'Region', 
           SUM(opportunities.value) AS 'Value (R)'....
    
    GROUP BY SUBSTRING_INDEX(team_name, '-', 1)
    ORDER BY cf_lu_types_fields_dropdown.values;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to group 3 objects in one view, and then center that view
In one statement I'm trying to group rows of one table by joining to
Hi my code doesn't work, Im trying to group my blogentries by year and
I am trying to convert this code from C# to VB. Tried to use
I'm trying to group table values by date, and this HQL query works fine:
I am trying to group results from an observations table. My table contains stock
I'm trying to group a generic List<> in C#. The code compiles, but the
I am trying to group results returned by Core Data. I read that you
I'm trying to 'group' a string into segments, I guess this example would explain
I'm trying to get this LINQ to work but fails with the error. Cannot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.