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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:21:37+00:00 2026-05-25T22:21:37+00:00

I have a table with column1 and column2 (both of them contain TEXT). I

  • 0

I have a table with column1 and column2 (both of them contain TEXT). I want to get:

1) the count of unique rows of column1@table, case-insensitive

2) the count of unique rows of column1@table and column2@table, case-insensitive

SELECT count(*) AS unique_row1 FROM (SELECT DISTINCT lower(column1) FROM table);

SELECT count(*) AS unique_rows12 FROM (SELECT DISTINCT lower(column1),lower(column1) FROM table);

Is there a more efficient way to do it? Is there’s a way to do it in a one query? I use SQLite3.

Thanks in advance.

Edit (due to @ypercube’s response):
Collation was default (case-sensitive, at least I didn’t do COLLATE NOCASE anywhere).

Also I’ve made a test and with COLLATE NOCASE it’s quite faster and the numbers are the same:

# time echo "SELECT count(DISTINCT lower(column1)), count(DISTINCT lower(column1 || column2)) FROM table;" | sqlite3 db.sqlite3
1643|5997
echo   0.00s user 0.00s system 25% cpu 0.003 total
sqlite3 db.sqlite3  0.58s user 0.04s system 96% cpu 0.643 total

# time echo "SELECT count(DISTINCT column1), count(DISTINCT column1 || column2) FROM table;" | sqlite3 db.sqlite3              
1658|6199
echo   0.00s user 0.00s system 36% cpu 0.002 total
sqlite3 db.sqlite3  0.42s user 0.04s system 95% cpu 0.483 total

# time echo "SELECT count(DISTINCT column1 COLLATE NOCASE), count(DISTINCT (column1 || column2) COLLATE NOCASE) FROM table;" | sqlite3 db.sqlite3
1643|5997
echo   0.00s user 0.00s system 32% cpu 0.002 total
sqlite3 db.sqlite3  0.43s user 0.04s system 98% cpu 0.481 total

COUNT(DISTINCT column1, column2) shows an error though: wrong number of arguments to function count(), but I hope I’ve got your idea.

  • 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-25T22:21:38+00:00Added an answer on May 25, 2026 at 10:21 pm

    You can try this:

    SELECT count(distinct lower(column1))
      FROM table
    

    And for the second:

    SELECT count(distinct lower(column1 || column2))
      FROM table
    

    Note: In this second case you must use coalesce if your columns can be nulls.

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

Sidebar

Related Questions

i have table structure with 3 colums (column1, column2, column3) and i want to
I have an HTML table with 2 columns. I want to show them both
I have a table say table1 which has 3 columns column1, column2 and column3
I have two columns(column1, column2) in my oracle database table named as demo .
I have table with following fields: father_id child_id Both of them should point to
I have a number of rows in the table, which datetime column values contain
I have two tables (lets call them table A and B) both of them
I have table Widgets and table Persons both of them contains Identity column (
Lets say I have 2 tables both of them contain dynamic columns and I
I have a table that has two columns both of them are continuous data.

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.