1

I have this website where I would allow the user to effectively parse the mysql database. I would like to present on the website the list of possible unique values from each column and hit an execute button to retrieve the data.

Is there a way to extract the unique values from the columns in a database? quickly? Before I was thinking of having some mapping file created before hand. I would ideally like this system to be fast. Any thoughts would be appreciated.

2 Answers 2

3

Like this?

select DISTINCT [column] from [table];

Sign up to request clarification or add additional context in comments.

9 Comments

This doesn't meet the speed requirement. I assume they are asking about a way of having them precalculated in an index or something.
He does not ask about speed and indexes but only about unique values. Please don't invent parts of the question :) The speed he refers to seems to be about a "scripted solution", seems to me the author simply did not know the DISTINCT keyword in SQL... seems he gave that answer an UP, too. Now I'm just not quite happy that the later response received the UP and mine did not :( :)
what is the speed on this? what if my database is 1 million + rows
The speed is very dependant on your setup, hardware, Indexes etc. Can you provide any more information? You can also try this and show us the Explain plan, it is usually a good starting point to assess performance.
What I take as a given: one has to have an index on all the columns that are named. That's true for any column ever named after "SELECT". Anyway, if you have that index the rest is up to your particular database, the hardware and its configuration - how much RAM is made available for certain types of cache, etc. I don't think one can give a general answer, it very much depends on the very concrete situation. One has to rely on the DB manufacturer to have implemented the best algorithm for that purpose, not much a DB user can do - if you WANT to execute that operation, you have to "pay" for it.
|
1
SELECT DISTINCT column_name FROM table_name;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.