Each transaction has two fields, trunk transaction hash and branch transaction hash, which refer to 2 other transactions (contain the hash of the entirety of these two transaction). When building transactions, you can set both of them, or you can set one of them (to promote it), or you can set none (both are determined by tip selection).
How exactly you set them depends on which library you are using.
But in general, except for bundles (which need to be connected directly, and all have the same bundle hash), you should not try to "group" transactions together manually - using the default tip selection will attach your transactions at the point where they are more likely to get confirmed fast. Deliberately attaching your transaction to 2 old transactions is a good way of making sure it will most likely never get confirmed.