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 6747845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:29:39+00:00 2026-05-26T12:29:39+00:00

I have the following MySQL query: SELECT Project.*, `trk_deleted`, `trk_status`, `trk_state` FROM `project` AS

  • 0

I have the following MySQL query:

SELECT Project.*, `trk_deleted`, `trk_status`, `trk_state` 
   FROM `project` AS `Project` LEFT JOIN `trackline` ON `prj_id` = `trk_project` 
   WHERE `prj_deleted` = '0' GROUP BY `prj_id` ORDER BY `prj_name`;

This is a bit hard to explain, but basically, I have a structure in my database where Projects have multiple Tracklines. Both of these entities have fields prj_deleted and trk_deleted respectively which can have a 1 value if it was deleted (hidden from view), or a 0 value is it is not deleted (still in view).

My Project view page shows icons for each project based on the tracklines in that project. These icons are displayed based on the values of trk_status and trk_state

My Project view page should only show the project 1 time, even if it has multiple tracklines (hence the GROUP BY prj_id)

My Problem:

From the Mysql Documentation on GROUP BY:

“Furthermore, the selection of values from each group cannot be influenced by adding an ORDER BY clause. Sorting of the result set occurs after values have been chosen, and ORDER BY does not affect which values the server chooses.”

My Project view page should ideally be displaying the icons for the tracklines that are not deleted. This is why I was hoping I could ORDER BY trk_deleted before the GROUP BY occurred so that grouping was done with a trackline that wasn’t deleted.

Hopefully someone can understand what I’m trying to get at here.

  • 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-05-26T12:29:40+00:00Added an answer on May 26, 2026 at 12:29 pm

    If you could provide some sample data and what you would like for the response, I could probably help with a better query. In the mean time:

    SELECT Project.*, MAX(`trk_deleted`), MAX(`trk_status`), MAX(`trk_state`)
    FROM `project` AS `Project` 
    LEFT JOIN `trackline` ON `prj_id` = `trk_project` AND trk_deleted = '0'
    WHERE `prj_deleted` = '0'
    GROUP BY `prj_id` ORDER BY `prj_name`;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following MySQL query statement: SELECT * FROM table1 INNER JOIN table2
I have the following MySql query: select t1.* from Table1 t1 inner join Table2
I have the following mysql query: $manufacturers_query = select m.manufacturers_id, m.manufacturers_name, m.manufacturers_image, mi.manufacturers_url from
I have the following MySQL query: SELECT value_1, ( SELECT value_4 FROM table_1 WHERE
I have the following mysql query: $products = mysql_query(SELECT * FROM dpweb_products WHERE id='$id')
I have the following query (MySQL): SELECT col1, col2 FROM database1.table ->WHERE col3 !=
I have a problem with the following MySQL query: SELECT * FROM TPDSessions WHERE
I have the following MySQL query: SELECT (COUNT(id) * 5) AS total FROM content
I have the following MySQL query: SELECT SUM(IF(num_content>3,3,num_content)) FROM ( SELECT DATE(FROM_UNIXTIME(content_timestamp)) as dt,
I have the following MySQL query: $imgDimensions_query = SELECT imgWidth, imgHeight FROM ( SELECT

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.