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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:36:03+00:00 2026-06-09T22:36:03+00:00

I want to select all the rows in a table that have a particular

  • 0

I want to select all the rows in a table that have a particular field property. Namely the field is one of a hundred thousand strings that are known.

I’m using R to send the query. So I have code which looks like:

my_samp <- sample(unique_ids, replace=T, size=10^6)  
my_conn <- dbConnect(MySQL(),user='me',dbname='my_db')
query <- paste('SELECT blah1, blah2,...,blah900 FROM my_table WHERE      blah1=',paste(my_samp,collapse=' OR ',sep=''),sep='')
res1 <- dbSendQuery(my_conn, query)
my_data <- fetch(res1,n=-1)
dbDisconnect(my_conn)

However, I fear that the string won’t be processed correctly by either the R interpreter or mysql. I also suspect that this is inefficient. Is there a cleaner solution?

I can’t read the whole table directly into R with dbReadTable as it’s too big.

I’m planning to do this several thousand times by forking the process – statistical bootstrapping.

There need to be duplicate records in the query if the string is repeated in my_samp.

  • 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-09T22:36:05+00:00Added an answer on June 9, 2026 at 10:36 pm

    The best way to do that is to:

    1. A) Create a subquery that creates that list of known strings or B) Insert the known strings into a table on the database
    2. Then A) create a new join query with those tables or B) use the “IN clause” with an immediate list as in:

      query <- paste('select * from my_table where blah1=',paste(my_samp,collapse=' OR ',paste(' in (str1, str2, str3, str4)',sep=''),sep=''),sep='')
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

let's say that you want to select all rows from one table that have
I want to SELECT all the rows from the table that correspond to a
I want to write a query to select from a table all rows with
I want to select all elements that have an accesskey defined on them. I
I want to select all nodes <cci:p> that do not have an attribute. So,
I have two table emptable1(empid,status) emptable2(empid,week) i want to select all the empid whose
I want to select all rows in a table but exclude some columns, it
I want to select multiple rows from checkbox and want to update them all
I want to select all categories from a webservice. The webservice does not have
Suppose I have a column called fruits I want to select all of the

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.