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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:41:10+00:00 2026-06-13T16:41:10+00:00

I have 27 tables in my database. One word table (a scrabble word list),

  • 0

I have 27 tables in my database. One word table (a scrabble word list), and 26 association tables.

Table  Fields
================
word   [id,word]
a      [word_id]
b      [word_id]
...
z      [word_id]

I’m trying to figure out matching words given a string.

For example, if the given string is pant, I want to know: pant, apt, pat, tap, ant, tan, nap, pan, at, ta, pa, an, na.

My current strategy is to explode each letter in the string and find the associated words that match all the letters.

For example:

SELECT word.word
FROM word, p, a, n, t
WHERE
    word.id = p.word_id OR
    word.id = a.word_id OR
    word.id = n.word_id OR
    word.id = t.word_id

But this ends up printing all words that have a p,a,n or t in them.

And if I switch all the operators to AND, I’m stuck with only one match: pant.

Can you help me solve this riddle?

I’m also concerned with how to handle duplicate letters in the string. For example, PPANT should find a match for app, when plain PANT should not.

Am I on the right track with the association tables or is there a better way?

I’m trying to handle this fairly efficiently in php/mysql. I’m aware there are others who have solved this riddle before in C, perl, java and the like.

  • 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-13T16:41:12+00:00Added an answer on June 13, 2026 at 4:41 pm

    I’m not familiar with MySQL’s advanced capabilities, so I cannot say if there is a way to do this restriction procedurally, which may save you a good amount of storage space. Nonetheless, I’ll offer this possibility.

    Say this was your word table:

    +==========+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+
    |   word   | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z |
    +==========+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+
    | pant     | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
    +==========+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+
    | ppant    | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 2 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
    +==========+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+
    | app      | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
    +==========+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+
    | kick     | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
    +==========+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+
    

    Then your query might look like the following:

    SELECT word.word FROM word
    JOIN
    (
      SELECT * FROM word WHERE word.word = "pant"
    ) AS root
    ON
        word.a <= root.a
    AND word.b <= root.b
    AND word.c <= root.c
    AND word.d <= root.d
    AND word.e <= root.e
    AND word.f <= root.f
    AND word.g <= root.g
    AND word.h <= root.h
    AND word.i <= root.i
    AND word.j <= root.j
    AND word.k <= root.k
    AND word.l <= root.l
    AND word.m <= root.m
    AND word.n <= root.n
    AND word.o <= root.o
    AND word.p <= root.p
    AND word.q <= root.q
    AND word.r <= root.r
    AND word.s <= root.s
    AND word.t <= root.t
    AND word.u <= root.u
    AND word.v <= root.v
    AND word.w <= root.w
    AND word.x <= root.x
    AND word.y <= root.y
    AND word.z <= root.z
    

    Now, of course there are ways to normalize the table and multiple ways to create the query. You should experiment with what makes most sense for your situation.

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

Sidebar

Related Questions

In a MySQL database I have two tables linked in a join. One table
I have 2 databases with a 2 tables with HierachyID fields. For one database
What I have is two tables inside of a mysql database. One table contains
I have a database with many tables and one particular table has columns: name
I have SMO code which copies tables from one database to another. It runs
I have two tables in my MySQL database, one is a library of all
I have two related tables in my database: Page and Tag. One Page can
I have database, and in one the tables I need change the values of
I have a database Student which contains about 20 tables. one of the tables
I have an existing database in mysql. One of my tables has discontinuous ids.

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.