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

  • Home
  • SEARCH
  • 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 6945107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:23:36+00:00 2026-05-27T13:23:36+00:00

I am trying to create a join statement to solve my problem but cannot

  • 0

I am trying to create a join statement to solve my problem but cannot get my head around it.

I am a new to join statements so please bear with me if my sql statement is nonsense.

I have two tables, one is a table of questions where users have asked questions about items for sale.

Second is a table of items that the user has asked a question about.

Table one called questions consists of question_ref, questioner_user_ref, item_ref, seller_ref, question_text, timestamp

questions
===========
+--------------+--------------------+---------+-----------+--------------+----------+
| question_ref |questioner_user_ref |item_ref |seller_ref |question_text |timestamp |
+--------------+--------------------+---------+-----------+--------------+----------+

Table two called my_item_comments consists of questioner_ref, item_ref, last_question_ref

my_item_comments
===========
+---------------+---------+------------------+
|questioner_ref |item_ref |last_question_ref |
+---------------+---------+------------------+

I have set up table two to keep track of items that the user has asked questions about so they can be informed when someone else asks the seller a question or the seller answers.

So I want to create a recordset of questions that
a). Someone has answered a question about an item the user is selling
b). A seller has replied to a question the user asked,
c). A third user has asked a question about an item that the user has also asked a question about.

A bit like facebook’s commenting system, where you are informed about comments people have made on statuses that you have commented on.

So my current sql statement is as follows

$user_ref= current logged in user


  $sql=mysql_query("
    SELECT * FROM questions
    LEFT JOIN my_item_comments
    ON questions.item_ref=my_item_comments.item_ref
    WHERE questions.questioner_user_ref!='$user_ref'
    AND (questions.seller_ref='$user_ref' OR questions.item_ref=my_item_comments.item_ref
    ORDER BY timestamp DESC");

The results don’t work and I think its because of the OR questions.item_ref=my_item_comments.item_ref but for the life of me I cannot work it out.

Any help would be greatly appreciated, even if it means restructuring my database with more tables or new fields in the tables.

thanks in advance, Barry

  • 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-27T13:23:37+00:00Added an answer on May 27, 2026 at 1:23 pm
    SELECT * FROM questions
    LEFT JOIN my_item_comments ON questions.item_ref=my_item_comments.item_ref
    WHERE 
       questions.questioner_user_ref != '$user_ref' AND 
       (questions.seller_ref='$user_ref' OR questions.item_ref=my_item_comments.item_ref)
    ORDER BY timestamp DESC
    

    I think you were missing a ) to enclose the OR clause (in the example above I added it)

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

Sidebar

Related Questions

I'm trying to create a named_scope that uses a join, but although the generated
Using extension syntax I'm trying to create a left-join using LINQ on two lists
I'm trying to create a record within a join table from the action of
I'm trying to create a record within a join table from the action of
I'm trying to create a relation that has a between join. Here is a
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
I am trying to create a query that allows me to get the sum
I'm having a rather strange problem with MySQL. Trying to create a procedure to
I am trying to create an update statement in Oracle. Here it is version
I am trying to create a select statement that uses the following structure: $db

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.