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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:34:06+00:00 2026-05-19T01:34:06+00:00

Ok, I have a database with with a table for storing classified posts, each

  • 0

Ok, I have a database with with a table for storing classified posts, each post belongs to a different city. For the purpose of this example we will call this table posts. This table has columns:

id        (INT, +AI),
cityid    (TEXT),
postcat   (TEXT), 
user      (TEXT), 
datatime  (DATETIME), 
title     (TEXT), 
desc      (TEXT), 
location  (TEXT)

an example of that data would be:

'12039',
'fayetteville-nc',
'user@gmail.com',
'December 28th, 2010 - 11:55 PM',
'post title',
'post description',
'spring lake'

id is auto incremented, cityid is in text format (this is where I think i will be losing performance once the database is large)…

Originally I planned on having a different table for each city and now since a user has to have the option of searching and posting through multiple cities, I think I need them all in one table. Everything was perfect when I had one city per table, where I could:

SELECT       *
FROM         `posts`
WHERE        MATCH (`title`, `desc`, `location`)
    AGAINST ('searchtext' IN BOOLEAN MODE)
  AND        `postcat` LIKE 'searchcatagory'

But then I ran into problems when trying to search multiple cities at one time, or listing all of a users posts for them to delete or edit.

So looks like I have to have one table with all the posts, and also match another FULLTEXT field: cityid. I am guessing I need full-text because if a user chooses an entire state, and my cityid is “fayetteville-nc” I would need to match cityid against “-nc” this is only an assumption and I would love another way. This database could easily reach over a million rows within 6 months, and a fulltext search against 4 columns is probably going to be slow.

My question is, is there a better way to do this more efficiently? The database has nothing in it now, except for some test posts made by me. So I can completely redesign the table structure if necessary. I am open to any and all suggestions, even if it is just a more efficient way to perform my query.

  • 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-19T01:34:07+00:00Added an answer on May 19, 2026 at 1:34 am

    Yes, one table for all posts sounds sensible. It would also be normal design for the posts table to have a city_id, referring to the id in a city table. Each city would also have a state_id, referring to the id in a state table, and similarly each state would have a country_id referring to the id in a country table. So you could write:

    SELECT $columns
    FROM posts JOIN city ON city.id = posts.city_id
    WHERE city.tag = 'fayetteville-nc'
    

    Once you’ve brought the cities into a separate table, it might make more sense for you to do the city-to-city_id resolving up front. This fairly naturally happens if you have a city chose from a dropdown, for instance. But if you’re entering free text into a search field, you may want to do it differently.

    You can also search for all posts in a given state (or set of states) as:

    SELECT $columns
    FROM posts
         JOIN city ON city.id = posts.city_id
         JOIN state ON state.id = city.state_id
    WHERE state.tag = 'NC'
    

    If you’re going to go more fancy or international, you may need a more flexible way of arranging locations into a hierarchy (e.g. you may want city districts, counties, multinational regions, intranational regions (Midwest, East Coast etc)) but stay easy for now 🙂

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

Sidebar

Related Questions

I have a database table called Posts which stores all the information regarding an
At the one end of my web application I have a database table storing
I have a database that contains a table for storing URL Images (since storing
I have a table in my database formatted like this: customer old_code new_code C1
I have a database with one of the table storing articles. For every article
In my application I have a sqlite database that looks like this: CREATE TABLE
I have a string column in a database table which maps to an Enum
I have data from a table in a database (string) that contain text and
I have a database table and one of the fields (not the primary key)
I have a database table that i want to allow my friends to update.

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.