Solved

PHP MySQL Not Equal Comparison between Two Tables

Posted on 2007-11-16
7
2,918 Views
Last Modified: 2010-04-21
I have two tables.  MySQL version 4.1.22-standard -  PHP 5.2.4.  

I'm trying to get the data from the Review Table that do not have entries in the Comment Table.  

Here's what I have..

First Table   Review - Fields ->  (item_id / date / user_id)  

Second Table Comments - Fields -> (comm_id, item_id, user_id,date)

Code Below.. Thanks..
SELECT Review.item_id, Review.date, Review.user_id, Comments.item_id
FROM Review, Comments
WHERE Review.item_id <> Comments.item_id

Open in new window

0
Comment
Question by:usiff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 20296803
You can try the SQL below
SELECT Review.item_id, Review.date, Review.user_id
FROM Review LEFT OUTER JOIN Comments on (Review.item_id = Comments.item_id)
WHERE Comments.item_id IS NULL

Open in new window

0
 
LVL 7

Expert Comment

by:dansoto
ID: 20297975

SELECT Review.item_id, Review.date, Review.user_id, Comments.item_id
FROM Review
WHERE Review.item_id NOT IN 
(SELECT Comments.item_id from Comments); 

Open in new window

0
 

Author Comment

by:usiff
ID: 20299640
Hello hernst42:

Here is another quick issue..

When I add this code below is doesn't work...
WHERE Comments.item_id IS NULL AND Review.user_id = $_SESSION['user_login_id']

But this will work?
WHERE Comments.item_id IS NULL AND Review.user_id = '444'

What the heck I'm I missing?

Thanks

usiff
0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
LVL 48

Expert Comment

by:hernst42
ID: 20299795
maybe $_SESSION['user_login_id'] is empty and does not contain anything. What do ypu get when you print out var_dump($_SESSION['user_login_id']) before you create the SQL?
0
 

Author Comment

by:usiff
ID: 20300288
Hello hernst42,

It's printing our string(1) "444"

It's crazy..
0
 

Author Comment

by:usiff
ID: 20300316
It's working now..  Wow...  I was going crazy!!  

I love typosss

Thanks again!

0
 

Author Closing Comment

by:usiff
ID: 31409512
Thanks!
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question