How do I join getting one row from the left table, no matter how many matches i get from the right table?

I have two tables – one is a data table and the other is a mapping table. I want to join them together, but only preserve the data from the right table. However, it is possible that the match table may contains multiple records that match to a single record in the right table. I cannot use a DISTINCT because there may be identical rows in the right table, and I want to preserve the same number of rows from the right-table in the result set.

Here is a sample of the data I am working with:

       DataTable                           MappingTable +-----+-----+-----+-----+           +------+------+------+------+ | ID1 | ID2 | ID3 | ID1 |           | ID1  | ID2  | ID3  | ID1  | +-----+-----+-----+-----+           +------+------+------+------+ |  1  |  1  |  1  |  1  |           |  1   | NULL | NULL | NULL | |  1  |  1  |  1  |  1  |           | NULL | NULL | NULL |  1   | |  2  |  1  |  1  |  1  |           |  3   |  3   | NULL | NULL | |  3  |  1  |  1  |  3  |           +------+------+------+------+ |  4  |  1  |  1  |  4  | |  2  |  2  |  1  |  1  | |  3  |  2  |  1  |  3  | |  3  |  3  |  1  |  3  | |  2  |  1  |  0  |  1  | |  2  |  1  |  0  |  1  | |  4  |  3  |  2  |  3  | +-----+-----+-----+-----+ 

Below is the join I am using. I wrote a custom function to handle the NULL-matching behavior, which I am including here as well.

SELECT * FROM DataTable P JOIN MappingTable M ON dbo.fNullMatchCheckIntS(P.ID1,M.ID1,0,1) = 1     AND dbo.fNullMatchCheckIntS(P.ID2,M.ID2,0,1) = 1     AND dbo.fNullMatchCheckIntS(P.ID3,M.ID3,0,1) = 1     AND dbo.fNullMatchCheckIntS(P.ID4,M.ID4,0,1) = 1 

CREATE FUNCTION dbo.fNullMatchCheckIntS (     @Value1 INT     ,@Value2 INT     ,@AutoMatchIfValue1IsNull BIT     ,@AutoMatchIfValue2IsNull BIT )     RETURNS BIT AS  BEGIN      DECLARE @Result BIT = 0      SELECT         @AutoMatchIfValue1IsNull = ISNULL(@AutoMatchIfValue1IsNull,0)         ,@AutoMatchIfValue2IsNull = ISNULL(@AutoMatchIfValue2IsNull,0)      IF         (@AutoMatchIfValue1IsNull = 1 AND @Value1 IS NULL)         OR (@AutoMatchIfValue2IsNull = 1 AND @Value2 IS NULL)         OR @Value1 = @Value2         OR (@Value1 IS NULL AND @Value2 IS NULL)     BEGIN         SET @Result = 1     END      RETURN @Result END 

The problem with the way the join works is that the first two rows in the DataTable match on the first two rows in the MappingTable, giving me four identical records in the result, but I only want 2. I know that I could add an identity column to the DataTable and then use DISTINCT or PARTITION to get the result I am looking for, but I would like to avoid that route if possible.

EDIT: I figured out a way to do this using EXISTS, but it looks a little ugly in my opinion. Still interested in other answers if anyone has an idea. Thanks!

SELECT * FROM DataTable D WHERE EXISTS (     SELECT D.ID1, D.ID2, D.ID3, D.ID4     FROM MappingTable M      WHERE dbo.fNullMatchCheckIntS(D.ID1,M.ID1,0,1) = 1         AND dbo.fNullMatchCheckIntS(D.ID2,M.ID2,0,1) = 1         AND dbo.fNullMatchCheckIntS(D.ID3,M.ID3,0,1) = 1         AND dbo.fNullMatchCheckIntS(D.ID4,M.ID4,0,1) = 1 ) 

How many vampire bites are undone by one casting of Greater Restoration?

A vampire’s bite deals 10 necrotic damage1 and also reduces the target’s maximum hit points by the same amount. Suppose I am at full health with 50 hit points, and a vampire bites me twice. My maximum hit points are now reduced to 30. (My current hit points are even lower since the bite also deals piercing damage, but that’s irrelevant to this question.) After the battle, my party cleric tries to heal this maximum hit point reduction by casting Greater Restoration on me, which can end

one effect reducing the target’s hit point maximum

What is my maximum hit point value now, after having Greater Restoration cast on me once? Does it remove the effect of a single bite, or all bites?

1It’s actually 3d6, but I’m abstracting the dice rolls since they’re not relevant to the question.

What is the best way to host a site with many images without it being too slow?

I have a friend that wants me to help them with their WordPress website that has about 150 images for their gallery. Their site is quite slow even after I optimized the images using the ImageOptim app. They are using SiteGround as their web host provider, but they are only using the StartUp package because it is the most affordable. I know that the site is slow to load because of the images, but not sure what the best approach is to try and speed it up without paying for a more expensive hosting package.

I am thinking that perhaps the best way to go about doing this would be to have them just put their images on Google Images and use that as their gallery instead, or maybe an Instagram feed like Smash Balloon.

What would you all suggest?


How many Sorcery Points should it cost to add 1d4 to a spell’s save DC?

I have a homebrew idea to try and add more power to the sorcerer. The idea is that when sorcerer casts a spell that causes a target to make a saving throw, they can spend sorcery points to add 1d4 to their spell save DC. I’m not sure how many sorcery points this should cost though and was wondering what other people think.

What happens to a devil who draws the balance card from a deck of many things? [duplicate]

This question already has an answer here:

  • What happens to a Devil when its alignment is forcibly changed? 1 answer

I recently read the accepted answer to this question, and this part brings a good question:

A devil does not choose to be lawful evil, and it doesn’t tend toward lawful evil, but rather it is lawful evil in its essence. If it somehow ceased to be lawful evil, it would cease to be a devil.

The effect of a Balance card from the Deck of Many things reads:

Balance: Your mind suffers a wrenching alteration, causing your Alignment to change. Lawful becomes chaotic, good becomes evil, and vice versa. If you are true neutral or unaligned, this card has no effect on you.

So if a devil draws the card and becomes chaotic good, and such a change means it ceases to be a devil, then what is it instead? How does it change?

When casting the Glyph of Warding spell, how many spell slots are used if you choose the Spell Glyph option?

The description of the spell states you can store a spell of 3rd level or lower by casting it as part of the Glyph of Warding.

Does this require the use of one spell slot (because you are casting it as ‘part’ of casting the glyph), or two spell slots (one for the glyph and one for the stored spell)?

Also if it does expend two spell slots, when is the second slot expended? Is it expended upon storing it? Or upon the glyph’s activation, which then casts the stored spell?

How many RAW dependencies are present in these instructions?

What is the number of RAW dependencies in below set of instructions?

I1: R1 = R2 - R3 I2: R2 = R1 + R3 I3: R3 = R1 + R2 I4: R1 = R2 - R2 

I can see the following RAW dependencies in it:

$ I_2-I_1\ for\ R_1$ ……… (a)

$ I_3-I_1\ for\ R_1$ ……… (b)

$ I_3-I_2\ for\ R_2$ ……… (c)

$ I_4-I_2\ for\ R_2$ ……… (d)

I think taking (a) and (b) implies that (c) has already been included. So, should this be counted as 4 RAW dependencies or 3 RAW dependencies?

GURPS – How many character points would cost a skill to fully manipulate an element?

One of the major advantages of GURPS is creating your character the way you want, since the rules let you create anything. And the spell-casting system is arguably too complex or boring. Putting together those two ways of thinking there is a sub-system that I inherited as GM where the players can cast spells without the casting time plus they don’t have to learn spell by spell to do something like tossing a fireball, there is a “Fire Manipulation” generic spell where the PC that acquires it can freely manipulate fire (or any other element – according to the skill) having the cost in mana scale up to how much he wants to manipulate.

That’s obviously too OP, but I managed to balance it with the encounters in the adventures so far, the problem is that I’m reviewing the rules of this sub-system we are using and I’m having trouble calculating how much it would cost in character points for such a spell.

Such a spell would put together in one multiple spells of the basic system, plus remove the combined casting times. To exemplify: One could cast a fireball at cost of 1 mana, or cast a wall of fire having the cost in mana depending on how many hexagons it would occupy.

How many character points would cost such skill?

That could be in 3rd or 4th editions.

Are there statistics on how many encounters-per-day most tables have? [closed]

Is there a consensus on how many combat encounters most players experience in a DnD 5E adventuring day?

From the DMG, pg 84:

Assuming typical adventuring conditions and average luck, most adventuring parties can handle about six to eight medium or hard encounters in a day.

However, this is more of a guideline, and doesn’t tell us how real players really play.

Security risk of encrypting the same data with many public keys

I need to distribute a shared 256 bit key to 100’s or 1000’s of nodes (I have the public key of each node).

There’s no networking involved – this will all be done by loading a single file on to each node. That file is generated by a “master”.

In some cases, the nodes use 2048-bit RSA keys, and others it is a p521 Elliptic Curve key.

The idea is to create a line for each node in the distributed file encrypting the shared key.

If the node uses EC, then the node’s public EC and the master’s private EC keys are used to generate a symmetric key which is used to encrypt the shared key . The encrypted shared key and signature generated by the master are stored on a line in the file. The node would then loop through each line in the file, use the master’s public EC key and its own private EC key to generate the same symmetric key, decrypt the data, then check the signature. If correct, then that is the shared key.

If the node uses RSA, then the shared key would be encrypted with the node’s public RSA key, and a signature generated by the master and both stored on a line in the file. The node would then loop through each line in the file, use its private RSA key to decrypt the data, then check the signature. If correct, then that is the shared key.

My worry is that does knowing that a single piece of data being encrypted with 1000 different keys give an attacker a significant advantage for deriving a private key?