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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:15:59+00:00 2026-06-07T14:15:59+00:00

I am trying to select multiple columns, but not all of the columns, from

  • 0

I am trying to select multiple columns, but not all of the columns, from the database. All of the columns I want to select are going to start with “word”.

So in pseudocode I’d like to do this:

SELECT "word%" from searchterms where onstate = 1;

More or less. I am not finding any documentation on how to do this – is it possible in MySQL? Basically, I am trying to store a list of words in a single row, with an identifier, and I want to associate all of the words with that identifier when I pull the records. All of the words are going to be joined as a string and passed to another function in an array/dictionary with their identifier.

I am trying to make as FEW database calls as possible to keep speedy code.

Ok, here’s another question for you guys:

There are going to be a variable number of columns with the name “word” in them. Would it be faster to do a separate database call for each row, with a generated Python query per row, or would it be faster to simply SELECT *, and only use the columns I needed? Is it possible to say SELECT * NOT XYZ?

  • 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-07T14:16:02+00:00Added an answer on June 7, 2026 at 2:16 pm

    No, SQL doesn’t provide you with any syntax to do such a select.

    What you can do is ask MySQL for a list of column names first, then generate the SQL query from that information.

    SELECT column_name
    FROM information_schema.columns
    WHERE table_name = 'your_table'
        AND column_name LIKE 'word%'
    

    let’s you select the column names. Then you can do, in Python:

    "SELECT * FROM your_table WHERE " + ' '.join(['%s = 1' % name for name in columns])
    

    Instead of using string concatenation, I would recommend using SQLAlchemy instead to do the SQL generating for you.

    However, if all you are doing is limit the number of columns there is no need to do a dynamic query like this at all. The hard work for the database is selecting the rows; it makes little difference to send you 5 columns out of 10, or all 10.

    In that case just use a "SELECT * FROM ..." and use Python to pick out the columns from the result set.

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

Sidebar

Related Questions

I am trying to pull multiple columns from 3 joined tables, but I want
I am trying to display the RowID alongside all columns from a Select *
Using PHP and MySQL I'm trying to select unique values from multiple columns in
I am trying to select three values from xml document. I want to get
I am trying to select an object from this array and print all of
I'm trying to select all dom elements that have id=mydiv but exclude the ones
I have a database storing multiple columns and I am trying to create efficient
I am trying to write a query that would select data from multiple lines
I've done all of this in active record, but it's not going to work
I'm trying to SELECT fields with multiple dots ( . ) in their value.

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.