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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:08:32+00:00 2026-05-26T15:08:32+00:00

I have two tables: conversation_participants id | conversation_id | user_id int(11) | int(11) |

  • 0

I have two tables:

conversation_participants

id      | conversation_id | user_id
int(11) |  int(11)        |   int(11)

users

id      | username   | ....
int(11) | varchar(20)| ....

I am trying to select all the users which have a certain string in their username which are not (yet) participants in a particular conversation. Currently I have two SQL queries:

SELECT user_id FROM conversation_participants WHERE conversation_id=?

and

SELECT id, username from users WHERE username LIKE '%%%{$_GET['q']}%%' ORDER BY id DESC LIMIT 10

And remove all the results from the second query which have the same user_id as the ones from the first query. Is there any way to merge these two queries into one ?

Thank you in advance

  • 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-26T15:08:33+00:00Added an answer on May 26, 2026 at 3:08 pm
    SELECT id, username from users 
    WHERE username LIKE '%%%{$_GET['q']}%%' 
    and username not in 
    (
      SELECT user_id FROM conversation_participants 
      WHERE conversation_id=users.conversation_id
    )
    ORDER BY id DESC LIMIT 10
    

    Don’t build your sql statements concatenating strings. You should use some sort of utility method to sanitize your input. Your statement is prone to sql injection attacks.

    PHP has several functions for this. Look into mysql_real_escape_string

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

Sidebar

Related Questions

I have two tables Users and messages: How i can make select full the
I have two tables: Unit: UnitId int PK Title varchar UnitOption: UnitOptionId int PK
I have two tables user table user_id | name | 1 | peter |
I have two tables, a user table and a application table: User id username
I have two tables in my MySQL database, one is a library of all
I am trying to return all MSFT Lync Users who have used voice conferencing
Here's the situation. I have two tables: users (registered users of the website), messages
I have a site 'accounts' table which contains account details for all our users.
I have two tables images2 and image_data So the goal is to have 1
I have two tables 1.Products prod_id prod_name 1 honda 2 hero 3 marcedes 4

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.