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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:37:11+00:00 2026-05-28T00:37:11+00:00

Hi is there a possibility to make a distinct select request to mnesia ?

  • 0

Hi is there a possibility to make a distinct select request to mnesia ?

I could copy the content of one table to ets and since ets is a hash table it could work. But i thought there is maybe a more elegant solution to this problem.

Thank you.

  • 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-28T00:37:12+00:00Added an answer on May 28, 2026 at 12:37 am

    I’m not sure if this is what you had in mind, but you could use QLC’s {unique, true} option (See QLC documentation for more info).

    I created a mnesia table, called test, with bag semantics. Each row consists of the table name, a Key and a Value, so my rows looked like:

    1. test, 1, 1
    2. test, 2, 1
    3. test, 2, 2
    4. test, 3, 1
    5. test, 3, 2
    6. test, 3, 3
    ... etc.
    

    Then this simple module illustrates my approach. Notice that you have to include the qlc library and that, in my example, I am selecting distinct Keys.

    -module(test).
    -export([select_distinct/0]).
    
    -include_lib("stdlib/include/qlc.hrl").
    
    select_distinct()->
        QH = qlc:q( [K || {_TName, K, _V} <- mnesia:table(test)], {unique, true}),
        F = fun() -> qlc:eval(QH) end,
        {atomic, Result} = mnesia:transaction(F),
        Result.
    

    Compiling and running

    > c("/home/jim/test", [{outdir, "/home/jim/"}]).
    > test:select_distinct(). 
    > [4,1,2,3,5]
    

    If you wanted sorted output then use the following version of the QH = … line above

        QH = qlc:sort(qlc:q( [K || {_TName, K, _V} <- mnesia:table(test)], {unique, true})),
    

    If you wanted to select distinct values, the following would work:

    QH = qlc:sort(qlc:q( [V || {_TName, _K, V} <- mnesia:table(test)], {unique, true})),
    

    Again, the code is just to illustrate an approach

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

Sidebar

Related Questions

Is there a possibility to make the default input-values dependent on one of the
Is there any possibility to make a link or a button to close the
If there is any possibility to make this code simpler, I'd really appreciate it!
Is there any possibility to select a option field by default in a g:select
Is there any possibility to copy variable by reference no matter if its int
is there a possibility to make perltidy vertically align brackets like this: $foo->bar (1);
Is there any possibility to make update in the database by using LINQ only
There is possibility to make global filter in DWR (direct web remoting). For example
Is there any possibility to make compiler continue when errors are encountered during the
I have a simple question. Is there a possibility to make an add-on for

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.