Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Query Design Help: Finding duplicates in multiple tables & exclusions
    primarykey
    data
    text
    <p>I am trying to design a query that picks up duplicate records from across two tables based on a few fields. I've set up what I've done so far here: <a href="http://sqlfiddle.com/#!2/e36c8d/1/0" rel="nofollow noreferrer">http://sqlfiddle.com/#!2/e36c8d/1/0</a></p> <p>Some context:</p> <p>1) These two tables identified below house 'items' for a game that players play. Items come from either drops from monsters/player trades.</p> <p>2) Players in the game are identified by their CharID</p> <p>3) Items are primarily defined by the following unique fields: Name, ItemID, ID1, ID2, ID3.</p> <p>4) There are other attributes for each item, but these can be changed depending on what the player does (e.g. changes colour of item; moves it position, upgrades it).</p> <p>5) There are two tables where items are stored: ITEM and BANKITEM. Item = bag; Bankitem = warehouse.</p> <p>There are occasions where players can (accidentally, or intentionally) duplicate individual items and then trade those items to other players or use on another one of their characters.</p> <p>Needs (Really important to meet all 3 needs):</p> <p>1) I need the query to scan both tables simultaneously to identify items that have duplicate Name, ItemID, ID1, ID2, ID3 that I can then investigate further (and delete one of the duplicates).</p> <p>2) I need the query to exclude certain items based on Name (e.g., RedPotions all have the same Name, ItemID, ID1, ID2, and ID3. These are common items and duplicates are fine...I don't need them included in the listing as they are not rare/high value items).</p> <p>3) I need the query to exclude CharID that are NULL <em>(This is where I am having real difficulty because CharID is not part of my SELECT statement, and it can't be because it is entirely possible for two different CharIDs to have the same duplicate rare item).</em></p> <p>SQL FIDDLE:</p> <p>If the query was working properly, the results should show:</p> <ul> <li><p>2 duplicate ChainHose(M) with the following common fields: ChainHose(M), 100, 17089, 22452, -12225</p></li> <li><p>The ChainHose(M) with the CharID of '0' would be excluded from the listing. Note the actual field in the table is NULL and not '0'. (I am new to SQL/SQL Fiddle and wasn't sure how to make it 'NULL' in SQL Fiddle for example purposes.</p></li> <li><p>2 duplicate Hauberk(W) with the following common fields: Hauberk(W), 200, 12369, 15252, 95682. It doesn't matter that the colour and lifespan are different (player with the duplicate could have dyed the armour after obtaining the duplicated item. The lifespan could have been reduced through use).</p></li> </ul> <p>Does anyone have any advice? I've previously asked a similar question without resolve (see <a href="https://stackoverflow.com/questions/20164449/advanced-sql-query-design-help-duplicates-across-two-tables-multiple-fields-p?answertab=active#tab-top">Advanced SQL Query Design Help (Duplicates across two tables, multiple fields, possible exclusions based on one field)</a>). The person recommended I be more specific and to use SQL Fiddle, so I have done so in hopes I can get this working properly.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload