Advertisement
MatthijsFontys

Many To Many Queries

Dec 15th, 2020
1,900
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.79 KB | None | 0 0
  1. -- Queries creating new 3D Object with existing tags
  2.  
  3.  
  4. INSERT INTO Object3D (name, path) VALUES ('new name', 'new path');
  5.  
  6. SELECT Id FROM Tag WHERE Name = 'MyTagName'.
  7. INSERT INTO Object3DTag (Object3DId, TagId) VALUES (193, 12);
  8. INSERT INTO Object3DTag (Object3DId, TagId) VALUES (193, 13);
  9. INSERT INTO Object3DTag (Object3DId, TagId) VALUES (193, 14);
  10.  
  11. -- Queries creating new 3D Object with new tags
  12.  
  13. INSERT INTO Object3D (name, path) VALUES ('new name', 'new path');
  14.  
  15. INSERT INTO Tag(name) VALUES('MyTagName');
  16.  
  17. INSERT INTO Object3DTag(Object3DId, TagId)
  18. VALUES (SELECT Id FROM Object3D WHERE Name = 'new name', SELECT Id FROM Tag WHERE Name = 'MyTagName'));
  19.  
  20.  
  21. -- Select the result.
  22. SELECT * FROM object3DTag JOIN tag ON tagId = tag.id JOIN object3D ON object3DId = object3D.id;
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement