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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:32:46+00:00 2026-06-03T02:32:46+00:00

i need to extract the last comment for each profile, for the last 100

  • 0

i need to extract the last comment for each profile, for the last 100 profiles

each profile, if type==1, has at least 1 comment

  • type==1 => is company
  • type==2 => is human

Here are the relevant tables and data:

CREATE TABLE IF NOT EXISTS `comment` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `profile` int(11) NOT NULL,
  `name` varchar(200) NOT NULL,
  `email` varchar(200) NOT NULL,
  `county` int(11) NOT NULL,
  `comment` text NOT NULL,
  `created` int(11) NOT NULL,
  `status` int(11) NOT NULL,
  `verified` int(11) NOT NULL,
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

INSERT INTO `comment` (`id`, `profile`, `name`, `email`, `county`, `comment`, `created`, `status`, `verified`) VALUES
(1, 1, 'ANGAJAT 1', 'email 2', 1, 'comm 1', 1335423985, 0, 0),
(2, 3, 'ANGAJAT 2', 'email 4', 1, 'comm 2', 1335424011, 0, 0),
(3, 5, 'ANGAJAT 3', 'email 6', 1, 'comm 3', 1335424037, 0, 0),
(4, 5, 'ANGAJAT 3', 'email 6', 1, 'comm 4', 1335424039, 0, 0);

CREATE TABLE IF NOT EXISTS `profile` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `type` int(11) NOT NULL COMMENT '1 = angajatori ; 2 - angajati',
  `name` varchar(200) NOT NULL,
  `county` int(11) NOT NULL,
  `email` varchar(200) NOT NULL,
  `created` int(11) NOT NULL,
  `comments` int(11) NOT NULL,
  `status` int(11) NOT NULL,
  `verified` int(11) NOT NULL,
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;

INSERT INTO `profile` (`id`, `type`, `name`, `county`, `email`, `created`, `comments`, `status`, `verified`) VALUES
(1, 1, 'ANGAJATOR 1', 1, 'email 1', 1335423985, 0, 0, 0),
(2, 2, 'ANGAJAT 1', 1, 'email 2', 1335423985, 0, 0, 0),
(3, 1, 'ANGAJATOR 2', 1, 'email 3', 1335424011, 0, 0, 0),
(4, 2, 'ANGAJAT 2', 1, 'email 4', 1335424011, 0, 0, 0),
(5, 1, 'ANGAJATOR 3', 1, 'email 5', 1335424037, 0, 0, 0),
(6, 2, 'ANGAJAT 3', 1, 'email 6', 1335424037, 0, 0, 0);\

I tried :

SELECT * 
FROM COMMENT c
JOIN profile p ON p.id = c.profile
GROUP BY c.profile
ORDER BY c.created DESC , p.id ASC 
LIMIT 100

and I got :

id  profile name    email   county  comment created status  verified    id  type    name    county  email   created comments    status  verified
3   5   ANGAJAT 3   email 6 1   comm 3  1335424037  0   0   5   1   ANGAJATOR 3 1   email 5 1335424037  0   0   0
2   3   ANGAJAT 2   email 4 1   comm 2  1335424011  0   0   3   1   ANGAJATOR 2 1   email 3 1335424011  0   0   0
1   1   ANGAJAT 1   email 2 1   comm 1  1335423985  0   0   1   1   ANGAJATOR 1 1   email 1 1335423985  0   0   0

the query returns the first comment for the each 100 last companies

pls help with query

  • 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-03T02:32:47+00:00Added an answer on June 3, 2026 at 2:32 am

    Try this:

    SELECT c.* 
    FROM COMMENT c
    JOIN 
      (SELECT MAX(created_at) created_at, profile FROM COMMENT
       GROUP BY profile) p ON p.profile = c.profile AND p.created_at = c.created_at
    ORDER BY c.created DESC , p.profile ASC 
    LIMIT 100
    

    It should do the trick.

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

Sidebar

Related Questions

I need to extract the same type of information (e.g. First name, Last Name,
I need to extract Asia from this array. How can i do that. Here
I need a formula to extract the last two words in a cell using
I have a matrix which has multiple rows per ID. I need to extract
I have got field containing comma separated values. I need to extract the last
I need to extract the last occurrence of a substring enclosed in _()_ ,
I need to extract URPlus1_S2_3 from the string: Last one: http://abc.imp/Basic2#URPlus1_S2_3, using regular expression
I need to extract the last number that is inside a string. I'm trying
I am using an autocomplete Javascript function, and I need to extract the last
I need to extract only the last row from a multi-line string using regular

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.