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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:14:06+00:00 2026-06-07T12:14:06+00:00

My Query which I am sure can be optimized extensively but couldn’t say how

  • 0

My Query which I am sure can be optimized extensively but couldn’t say how off the top of my head.

What I have is a post/comment like concept going on for my members. Where they can choose to share it with specific people or everyone. So from this I know my query can potentially cause duplicate results (if I could get it to work in the first place). I need to get a distinct ‘ciID’ while finding the users ID, along with any potential ID’s mentioned else where. The ID’s for the members are stored in 3 different columns for 3 different reasons.

mID is the member themselves, then sharedWith and whos_with kinda speak for themselves. I store the id’s in sharedWith and whos_with like 1111:2222:3333 But in all I have to search across all 3 columns for the member ID shared, and whos column to make sure I get all the results for the ID’s being passed through a function in an array. Which after building the query through a loop I come up with a query like

select DISTINCT(ciID),* from user_posting 
where (mID = 21 OR sharedWith LIKE '%21%' OR whosWith LIKE '%21%') 
or (mID = 22 OR sharedWith LIKE '%22%' OR whosWith LIKE '%22%') 
or (mID = 45 OR sharedWith LIKE '%45%' OR whosWith LIKE '%45%')
limit 1

somewhere in that I have a syntax erro I am not noticing, and I need a pair of eyes to help me out

  • 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-07T12:14:08+00:00Added an answer on June 7, 2026 at 12:14 pm

    This is definitely wrong:

    select DISTINCT(ciID),* from user_posting 
    

    It should be:

    select DISTINCT(up.ciID), up.* from user_posting up 
    

    However I am not quite sure if that will return the expected results.

    I think you need to re-design your table structure. Selecting with LIKE doesn’t scale that good.

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

Sidebar

Related Questions

I'm using Oracle SQL Developer to query an Oracle DB (not sure which version
I have a Cypher query which starts by finding a list of nodes from
I have this query which on executing in my sql command line client executes
I have a query which returns two rows of data as count. I want
I have a simple query which queries by item_id and it obviously works because
I have a query which is updating the status of a user passed inside
I have following complex query which I need to use. When I run it,
I have this query which I want to run in my PHP application back
I have SQL SELECT query which returns a lot of rows, and I have
I really couldn't figure out a good title for this question, but I have

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.