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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:42:27+00:00 2026-06-14T03:42:27+00:00

A MySQL table has only 5 fields but hundreds of rows. With good advice

  • 0

A MySQL table has only 5 fields but hundreds of rows. With good advice (tks Lacoz) I have duplicated the table while ignoring the duplicate rows and now have a new table that does not contain the duplicated rows.

Problem: the new table was inputted in a scrambled order (i.e. when observing the first field, called rel_id). While this doesn’t matter in the real world, at this point it would be helpful to have them in the same order (for referring to past notes, etc).

Example Row: (Note that rel_id is an auto-incrementing, primary key field)

'rel_id' => 1
'host' => 17
'host_type' => 'client'
'rep' => 7
'rep_type => 'cli_mgr'

Here is the method by which user Lacoz assisted me to create the new table, without duplicates:

mysql_query("create table rels2 like rels");
mysql_query("alter table rels2 add unique index(host,host_type,rep,rep_type)");
mysql_query("insert IGNORE into rels2 select * from rels");

I tried adding “ORDER BY” to the final query, like this:

mysql_query("insert IGNORE into rels2 select * from rels ORDER BY rel_id");

but it didn’t solve the problem. Rows are still in scrambled order.

First Question: Why did this happen?

Second Question: How could I have ensured that the data was input in the correct order?

Necessary Outcome: For various reasons I really need the data returned to its former appearance (but sans the duplicates). Can someone suggest another approach, even a php script, to accomplish this?

PS: After several google searches I don’t think it’s possible to sort the table’s raw data, only the output. Correct? (It is hard to be sure when a novice to both the concepts and the terminology – we all must start somewhere).

  • 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-14T03:42:28+00:00Added an answer on June 14, 2026 at 3:42 am

    Conceptually, data in a relational database is not stored in any particular order. Mathematically, it’s a set or relations, and sets have no ordering. That’s why SQL doesn’t provide any way to insert rows in a certain sequence (e.g. insert this row at the end, at the beginning, after some other row, etc…). It only provides a way to filter the output of a query given some specified ordering criteria.

    Of course, a concrete implementation of SQL has to ultimately store things on disk in some kind of order, which is why you notice a repeatable ordering when you query a table without giving an ORDER BY clause, but you can’t count on it. Your software should assume that rows will come out in arbitrary order.

    If you need results to come out in a particular order, use ORDER BY on the query. Maybe build an appropriate index (if there isn’t one already) to make sure the database can produce the ordering you request with good performance.

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

Sidebar

Related Questions

I have MySQL InnoDB table utf-8 encoded. This table has only id and name
the mysql table below has two columns. how do i select only those rows
I have a huge MySQL table which has its rows encoded in UTF-8 twice.
I have a MySQL database table called 'Videos' with only three columns (fields?): ID,
I have two tables: products products_tmp The products_tmp table has less fields. But all
I have a table which has two fields. There can be multiple rows with
I have a MySQL table which has a product_id field (big integer) 1102330008 1102330025
I have mysql table that has a column that stores xml as a string.
I have a mySQL table that has a column like this: ID ----- 0352
I have a MySQL table that has a field of comma separated values. How

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.