home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Help on running a specific SQL statement

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2470
Discussions: 200,959, Posts: 2,379,551, Members: 246,329
Old June 18th, 2008, 05:23 PM   Digg it!   #1 (permalink)
Ultimate Member
 
Tekk's Avatar
 
Join Date: Oct 2001
Location: Pasadena, CA
Posts: 2,177
Help on running a specific SQL statement

So Im trying to figure out how to compare two tables and get a listing of records that do NOT appear in the other.

Table 1 contains information that Im comparing to Table 2 and I want any records in T1 that do NOT appear in T2 to show in the results. I have some examples below:

Code:
TABLE 1
T-Code		Auth_Object		Attribute	Attribute Value
-----------------------------------------------------------------------------
ME21		M_BEST_BSA		ACTVT		01
ME21		M_BEST_BSA		ACTVT		02
ME21		M_BEST_BSA		BSART		XX
ME21		M_BEST_EKG		ACTVT		01
ME21		M_BEST_EKG		EKGRP		XX

TABLE 2
T-Code		Auth_Object		Attribute	Attribute Value
-----------------------------------------------------------------------------
ME21		M_BEST_BSA		ACTVT		01
ME21		M_BEST_EKG		ACTVT		01
So when running the proposed query against the above data, I would want the following records to be included in the results:

Code:
T-Code		Auth_Object		Attribute	Attribute Value
-----------------------------------------------------------------------------
ME21		M_BEST_BSA		BSART		XX
ME21		M_BEST_BSA		ACTVT		02
ME21		M_BEST_EKG		EKGRP		XX
Any help in creating a query that will assist me in running this on a multitude of records in the tables? Thanks in advance.
__________________
YAH! I knew you'd be jealous
Tekk is offline   Reply With Quote
Old June 18th, 2008, 09:21 PM     #2 (permalink)
Super F@D Folder
 
Join Date: Jun 2004
Posts: 5,083
Send a message via AIM to sr71000
anything like this?

[thelist] MySQL comparing two tables
sr71000 is offline   Reply With Quote
Old June 18th, 2008, 09:48 PM     #3 (permalink)
Not Really a Member
 
Join Date: Oct 2001
Posts: 25,391
Quote:
Originally Posted by sr71000 View Post

I would go with the join method in mentioned in this article

T-Code Auth_Object Attribute Attribute Value


select *
from table 1 t1
LEFT OUTER join table2 t2
on t1.[t-code] = t2.[t-code]
LEFT OUTER join table2 t2
on t1.[auth_object] = t2.[auth_object]
LEFT OUTER join table2 t2
on t1.[Attribute] = t2.[Attribute]
LEFT OUTER join table2 t2
on t1.[Attribute Value] = t2.[Attribute Value]
WHERE [t-code] IS NULL
OR [auth_object] IS NULL
OR Attribute IS NULL
OR [Attribute value] IS NULL

btw, this will give you half the results you want, you can figure out the rest


FYI I REALLY dont like the structure of this table

1. Spaces in column names
2. hyphens in column names
3. No standard in seperating words (I typically change case of first letter in each word AttributeValue). If you dont like changed case, then keep with underscore, with hyphens you have to use brackets and they're just annoying
4. Attribute and Attribute value probably shouldn't be in the same table.

Last edited by vass0922 : June 18th, 2008 at 09:51 PM.
vass0922 is online now   Reply With Quote
Old June 19th, 2008, 10:05 AM     #4 (permalink)
Caveat Emptor
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 3,241
Send a message via AIM to Rootstonian
SELECT
A.T-CODE,
A.AUTH_OBJECT,
A.ATTRIBUTE,
A.ATTRIBUTE VALUE
FROM TABLE1 A
WHERE NOT EXISTS
(SELECT 'X'
FROM TABLE2 B
WHERE
A.T-CODE = B.T-CODE
AND A.AUTH_OBJECT = B.AUTH_OBJECT
AND A.ATTRIBUTE = B.ATTRIBUTE
AND A.ATTRIBUTE VALUE = B.ATTRIBUTE VALUE)
Rootstonian is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
forming SQL Insert statement ShuckyD Webmastering and Programming 5 August 1st, 2007 08:49 AM
SQL statement help (pretty basic) ZeR0 Webmastering and Programming 2 February 23rd, 2006 01:38 PM
Running SQl server Scripts Sunayana Webmastering and Programming 2 October 25th, 2002 06:01 PM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (2975)
The disrespect of Obama by Russian .. (45)
Making Health Care Worse (181)
Wireless Televisions. (12)
CPU fan stops spinning randomly (10)
Regular Build (11)
windows 7 problem (7)
Laptop with wireless problem. (5)
windows vista security holes (13)
Is the PSU I received dead? (13)
Point and Shoot Camera Suggestions. (5)
Print spooler problem (16)
radeon x850xt platinum & shader.. (6)
HIS HD5770 graphic card question (15)
Recent Discussions
Point and Shoot Camera Suggestions. (5)
CPU fan stops spinning randomly (10)
Is the PSU I received dead? (13)
Print spooler problem (16)
Nvidia GTX 260 problem (0)
windows vista security holes (13)
Kingston Bluetooth Dongle Driver (1)
Multiple Restarts Required at Boot (3)
Open With ..... Win7 (1)
webcam (0)
upgrade for hp a6101 (0)
Laptop with wireless problem. (5)
Modern Warfare 2: Who Bought It? (64)
tv not turn on-makes clicking sound (2)
EVGA 9800 gtx help with finding a goo.. (11)
Regular Build (11)
Help with onclick and buttons (0)
Virus advise (8)
My monitor won't turn on after instal.. (1)
Internet Lost (3)
Dept. of HS: NSA 'Helped' Develop Vis.. (16)
Ideal cheap graph card for PC-Gaming? (18)
radeon x850xt platinum & shader 3 (6)
Graphics Card Upgrade Question (4)
For Sale BFG GTX285 OC2 with 10 year .. (3)


All times are GMT -4. The time now is 10:57 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28