Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

SQL JOIN

Posted on 2011-05-12
3
Medium Priority
?
355 Views
Last Modified: 2012-05-11
I have 2 tables that look like this

table_prodsize
prodsizeid | prodize
--------------  -------------

     16           X-small
     17           Small
     18           Medium
     19           Large


table_sizes

productid | sizeid
------------   ---------

      1          17
      1          18
      1          19

I am trying to get records to show that DON'T match. So basically X-small should show as it is the only one not in the table_sizes table but my query is not doing that. Pleas help!

SELECT *
FROM sizes INNER JOIN prodsize ON sizes.sizeid != prodsize.prodsizeid
WHERE productid = colname

colname:

$colname_rs_sizes = "-1";
if (isset($_GET['ProductID'])) {
  $colname_rs_sizes = $_GET['ProductID'];
}

0
Comment
Question by:jonofat
  • 2
3 Comments
 

Author Comment

by:jonofat
ID: 35748149
sorry, that != is meant to be <>, i forgot to change it back...
0
 
LVL 13

Accepted Solution

by:
haloexpertsexchange earned 2000 total points
ID: 35748250
Try this.
select * from sizes where size not in (SELECT size
FROM sizes INNER JOIN prodsize ON sizes.sizeid = prodsize.prodsizeid
WHERE productid = colname)

Open in new window

0
 

Author Comment

by:jonofat
ID: 35748312
Okay, you muddled the order around a bit so I tried it with the order I want and it worked like a charm! Great stuff, thanks so much! Points on the way..

SELECT *
FROM prodsize
WHERE prodsizeid not in (SELECT sizeid FROM sizes INNER JOIN prodsize ON sizes.sizeid = prodsize.prodsizeid WHERE productid = colname)
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

580 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