Solved

PHP MySQL Not Equal Comparison between Two Tables

Posted on 2007-11-16
7
2,920 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

615 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