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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:10:23+00:00 2026-06-08T17:10:23+00:00

I have this query… $sQuery = SELECT SQL_CALC_FOUND_ROWS .str_replace( , , , implode(, ,

  • 0

I have this query…

    $sQuery = "
        SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
        FROM   dominios left join datas on dominios.id_dominio=datas.id_dominio
left join dnss on dominios.id_dominio=dnss.id_dominio
left join entidades_gestoras on dominios.id_dominio=entidades_gestoras.id_dominio
left join estados on dominios.id_dominio=estados.id_dominio
left join ips on dominios.id_dominio=ips.id_dominio
left join quantidade_dnss on dominios.id_dominio=quantidade_dnss.id_dominio
left join responsaveis_tecnicos on dominios.id_dominio=responsaveis_tecnicos.id_dominio
left join titulares on dominios.id_dominio=titulares.id_dominio 
        WHERE dominios.estado not like 2 and dominios.estado not like 0 AND data_expiracao > '".date("Ymd")."' $sWhere $where 
        GROUP BY dominio 
        $sOrder
        $sLimit
        ";

It returns me the results I ‘need’…
But the Group By, it show me the first result that appear on the database, and I needed the last…

How can I do this? :s

Edited
This is the final query, without those variables

  SELECT SQL_CALC_FOUND_ROWS `datas`.`data_insercao`, `datas`.`data_expiracao`, `datas`.`data_registo`, 
`dominios`.`dominio`, 
`titulares`.`nome`, `titulares`.`morada`, `titulares`.`email`, `titulares`.`localidade`, `titulares`.`cod_postal`, 
`entidades_gestoras`.`nome`, `entidades_gestoras`.`email`, 
`responsaveis_tecnicos`.`nome`, `responsaveis_tecnicos`.`email`, 
`ips`.`ip`, `dominios`.`id_dominio` FROM dominios left join datas on dominios.id_dominio=datas.id_dominio 
left join dnss on dominios.id_dominio=dnss.id_dominio 
left join entidades_gestoras on dominios.id_dominio=entidades_gestoras.id_dominio 
left join estados on dominios.id_dominio=estados.id_dominio 
left join ips on dominios.id_dominio=ips.id_dominio 
left join quantidade_dnss on dominios.id_dominio=quantidade_dnss.id_dominio 
left join responsaveis_tecnicos on dominios.id_dominio=responsaveis_tecnicos.id_dominio left join titulares on dominios.id_dominio=titulares.id_dominio WHERE dominios.estado not like 2 and dominios.estado not like 0 AND data_expiracao > '20120730' GROUP BY dominio ORDER BY `datas`.`data_insercao` asc LIMIT 0, 10
  • 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-08T17:10:24+00:00Added an answer on June 8, 2026 at 5:10 pm

    General considerations

    I’m not sure what columsn you have in aColumns, or what table that dominio column comes from. When you group a number of rows using GROUP BY, then the columns you select for your result should either have the same value for all rows of the group (i.e. be functionally dependent), or should be some aggregate function combining the values of all the rows in the group.

    Some SQL dialects enforce this. MySQL doesn’t, but if you select an unaggregated column which has different values within the group, there are no guarantees as to what value will actually be returned to you. It might come from any row within the group. So there is no way to get the “last” of these rows, as there isn’t any inherent order. In simple cases you can use MIN or MAX to select the value you need. In more complicated cases, you’ll most likely have to use subqueries to do the selection from within the groups.

    For example, this answer computes for every Name (which corresponds to your dominio grouping column) the last value of Action based on an ordering by ascending Time. Or rather the first value using a descending ordering, which is the same.

    Your application

    As your comment below indicates that you want the maximal id_dominio for each dominio in dominios, I suggest the following:

    SELECT …
    FROM (SELECT MAX(id_dominio) AS id_dominio
          FROM dominios
          GROUP BY dominio
          WHERE estado <> 2
            AND estado <> 0
         ) domIds
    LEFT JOIN datas ON domIds.id_dominio=datas.id_dominio
    …
    

    So there will be one subquery to compute the maximal id_dominio for each dominio group, and all subsequent joins can use the IDs from that subquery instead of the full dominio table. If you need other columns from the dominio table as well, you might have to include that in the join again, so that you can get all the values from those row3s whose IDs you selected in the subquery.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query in Mysql SELECT z.virtuemart_product_id,z.product_name,d.product_price FROM x5lui_virtuemart_products x inner join x5lui_virtuemart_products_en_gb
I have this query: SELECT Auctions.ID FROM Auctions INNER JOIN Products ON Auctions.ProductID =
I have this query: SELECT page.id, revision.title, revision.number FROM page INNER JOIN revision ON
I have this query SELECT l.licitatii_id, l.nume, l.data_publicarii, l.data_limita FROM licitatii_ue l INNER JOIN
I have this query: SELECT DISTINCT(b.friend_id) AS possible_id FROM friends_friends a JOIN friends_friends b
I have this query: SELECT p.id, r.status, r.title FROM page AS p INNER JOIN
I have this query: SELECT COUNT(*) AS `numrows` FROM (`tbl_A`) JOIN `tbl_B` ON `tbl_A`.`B_id`
I have this query... SELECT Distinct([TargetAttributeID]) FROM (SELECT distinct att1.intAttributeID as [TargetAttributeID] FROM AST_tblAttributes
I have this query: SELECT * From checkfinale where AssociateID = 51 AND `CompletedDate`
I have this query: public function checkUser($phone) { $sql = SELECT name FROM users

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.