Idea

Cameron Pluim avatar image
4 Likes"
Cameron Pluim suggested Abhay Bajpai commented

Can DISTINCT be added as a keyword for queries?

I recently got into a situation where I wanted to know how many distinct values were in a column of a table. It would be nice to be able to use the following:

SELECT COUNT (DISTINCT column-name)  FROM table-name
sqlselect query
· 5
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Mischa Spelt avatar image Mischa Spelt commented ·

If you just want to know how many distinct values there are in a column, you could do something like

query("SELECT column-name FROM table-name GROUP BY column-name");
int distinctValues = getquerymatchcount();

Of course that only works in some pretty specific cases but it may be enough to help you go forward for now.

1 Like 1 ·
Cameron Pluim avatar image Cameron Pluim Mischa Spelt commented ·

Thanks @Mischa Spelt, I didn't understand exactly how GROUP BY works, but that should help a lot

0 Likes 0 ·
Abhay Bajpai avatar image Abhay Bajpai Mischa Spelt commented ·

How can I use DISTINCT to list out distinct values from the column into another table?

Already tried the following code and got the error "time: 0.000000 exception: FlexScript exception: Could not parse query SELECT DISTINCT ModelName FROM ProductionOrder at MODEL:/Tools/UserCommands/WriteStationMaps/code"

string sql4="SELECT DISTINCT ModelName \
FROM ProductionOrder";

Table result4=Table.query(sql4);
result4.cloneTo(Table("UniqueModelNames"));
0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Abhay Bajpai commented ·
DISTINCT isn's a keyword you can use - as it mentions on this page and in the documentation. Use:


SELCT ModelName From ProductionOrder GROUP BY ModelName

In future please post a new question.

1 Like 1 ·
Show more comments

1 Comment

martin.j avatar image
1 Like"
martin.j commented

The DISTINCT keyword does have its uses, but many problems where you need it can be solved by using the Group by statement: This will give you a list where each new distinction of column name has its own row. Now you can iterate through the distinctions.

SELECT COUNT(*), [column-name] FROM table GROUP BY [column-name]

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Your Opinion Counts

Share your great idea, or help out by voting for other people's ideas.