What you are describing is a polymorphic table. That sounds scary, but it's really not that bad.
You can store separate user and guest tables. For the Orders table, you have two columns: foreign_idand foreign_type(you can name them anything). foreign_idis the user or guest identifier in your case, and the content foreign_typewill be either user, or guest:
id | foreign_id | foreign_type | other_data
-------------------------------------------------
1 | 1 | user | ...
2 | 1 | guest | ...
To select rows for a specific user or guest, simply specify foreign_typealong with the identifier:
SELECT * FROM orders WHERE foreign_id = 1 AND foreign_type = 'guest';
source
share