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

  • Home
  • SEARCH
  • 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 8793139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:05:07+00:00 2026-06-13T23:05:07+00:00

I have a table1 containing duplicate column value Table1 id code 1 201202 0000

  • 0

I have a table1 containing duplicate column value

Table1

id   code
1   201202  0000    1111
2   201202  0000    9999
3   201203  0000    9999
4   201203  0000    0999
5   201204  1000    1999
6   201204  2000    2999
7   201205  3000    3999
8   201205  4000    4999
9   201205  5000    5999

Table 2

id   numbers
1   2012020010  
2   2012024929  
3   2012033838
4   2012052434
5   2012052229
6   2012052232

I want to count all the numbers in table2 that are substring of distinct code in table 1
i.e. result should be

code   frequency
201202   2
201203   1
201205   3

I have been able to get all the numbers for every code but can’t figure out how to count them

SELECT DISTINCT table1.code , table1.id, table2.number AS ph_npa, count( * )
FROM table1
INNER JOIN table2 ON substr( table2.number, 1, 6 ) = table1.code
GROUP BY table1.number

any help is appreciated.

  • 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-13T23:05:08+00:00Added an answer on June 13, 2026 at 11:05 pm

    ok I got it working and query is super fast

    SELECT

    DISTINCT A.code as code,
    B.Counts AS frequency
    FROM table1 AS A

    INNER JOIN (

    SELECT substr( number, 1, 6 ) AS subnumber, count( 1 ) AS Counts
    FROM table2
    GROUP BY substr( number, 1, 6 )
    )
    AS B ON A.code = B.subnumber

    i.e.
    select the number and frequency of number from table 2
    and then join with distinct code form table 1

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

Sidebar

Related Questions

Ok I have a data table containing duplicate Reciept numbers and a transaction value
I have data table containing one column as FilePath. FilePath D:\New folder\link.txt D:\New folder\SharepointMigration(Work
Possible Duplicate: Formating an SQL timestamp with PHP I have a column in my
I have a table containing a series of names, events and dates. I've created
I have a table containing the results of games played. I have another table
I have a table containing data about some users. Many of them use our
I have a table containing reports and the date/time they were created. I'd like
I have a table containing view/click records. The time is stored in a unix
I have a table containing cells with phone numbers. How can I allow the
I have a table containing 2 date fields and an identifier (id, fromdate and

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.