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

  • Home
  • SEARCH
  • 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 6207555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:39:05+00:00 2026-05-24T05:39:05+00:00

I’m new! New here, new with MySQL and PHP. And I’m trying to do

  • 0

I’m new! New here, new with MySQL and PHP. And I’m trying to do a little something which has got me all baffled up. Please try and help me guys.

I have a table with some sample data as follows:

ID  NAME    ATTRIBUTE
1   John     123
2   Sean     654
3   John     987
4   Audrey   458
5   John     123
6   Audrey   589
7   Peter    257
8   Marc     125
9   Audrey   326
10  Stan     456
11  Carol    698

And here’s a list of what I intend to do –

  1. Select the first 6 records

  2. Find Unique Names from the 6 selected records – Expected Result : 3 Unique Names (John, Sean & Audrey)

  3. Find the Number of Attributes for each Unique Name from the Selected 6 records – Expected Result: John (3 attributes) , Sean (1 attribute) and Audrey (2 attributes).

  4. Count the Number of identical attributes for each of the Unique name from the selected 6 records – Expected Result: Name=> John, Attribute=> 123, No. of Occurrence=> 2, Name=> John, Attribute=> 987, No. of Occurrence=> 1 etc.

  5. From the above selections, insert data to a new database table (e.g. Unique Names) in the format:

    a. NameID (Not the same one as the last table, new id – auto generated),
    b. Name

    And in another table (e.g. Attributes)

    a. ID(Auto Generated),
    b. Attribute,
    c. NameID (should be the same as ID in the last) – this is for the relationship between the Unique Names and Attributes table)
    d. Occurrence (of each attribute for each unique name)

  6. Once the new tables are filled with the data, I would like to Delete the top 6 selected record from the first table from where they are collected. (The Top Table)

Can someone help me with the MySQL queries and supporting PHP codes for this one. Also, I would like to know the best and fastest possible way to query the MySQL for the above if I have millions of data in the tables.

  • 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-24T05:39:06+00:00Added an answer on May 24, 2026 at 5:39 am

    Question 1:

    SELECT t.id,  t.name,t.attribute FROM t LIMIT 6
    

    Question 2:

    SELECT DISTINCT t.name FROM (SELECT t.id, t.name, t.attribute FROM t LIMIT 6) t
    

    Question 3:

    SELECT t.name, COUNT(t.attribute) AS number_of_attributes FROM(SELECT t.id, t.name, t.attribute FROM t LIMIT 6) t
    GROUP BY t.name
    ORDER BY number_of_attributes desc
    

    Question 4:

    SELECT t.name, t.attribute, COUNT(t.attribute) AS Appears FROM (SELECT t.id, t.name, t.attribute FROM t LIMIT 6) t
    GROUP BY t.name,t.attribute
    ORDER BY Appears desc
    

    Question 5:
    First part: Must be done in 2 steps, first select the unique names-from the top 6 first selected-, then add the auto_increment column:

    CREATE TABLE unique_names SELECT DISTINCT t.name FROM t
    
    ALTER TABLE unique_names ADD name_id INT AUTO_INCREMENT PRIMARY KEY FIRST
    

    Second part: the same as the first one, but in this case to get the id we join with the table created in the first part of this step, and then we add the auto_increment column

    CREATE TABLE attributes SELECT t.attribute,un.name_id FROM t INNER JOIN unique_names un ON t.name=un.name
    
    ALTER TABLE attributes ADD id INT AUTO_INCREMENT PRIMARY KEY FIRST
    

    Question 6:

    DELETE FROM t LIMIT 6
    

    In this case I used t as the original table name

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.