mysql - Did my union work? -
we in process of making in school version of facebook aka tigerbook now. have created following 3 data tables.
users:
user name 1 hallie 2 dylan 3 sarina 4 dominic
friends:
user friend 1 2 1 3 1 4 2 1 3 1 4 1 2 4 4 2 3 2 2 3
posts:
user postid post 1 101 tigerbook! 2 102 pregnant. 1 103 peeps 4 104 giant buzz lightyears rock. 3 105 die tucker die 1 106 murhur de derpity derp 2 107 banana spaghetti squid 4 108 chicken
we used syntax of:
select user users union select user friends union select user posts;
and came this:
user 1 2 1 4
all wondering if join worked or if should try else. we've tried left joins , full joins, nothing has worked well.
and on side note: when connect php code web page automatically generate users when create login or have create users before make login?
well that's not join
... it's union
removed duplicates of user
across 3 tables.. answer question, union
worked. if want join
users posts, need like
select a.user, a.name, b.postid, b.post users join posts b on b.user = a.user
this produces
| user | name | postid | post | --------------------------------------------------------- | 1 | hallie | 101 | tigerbook! | | 2 | dylan | 102 | pregnant. | | 1 | hallie | 103 | peeps | | 4 | dominic | 104 | giant buzz lightyears rock. | | 3 | sarina | 105 | die tucker die | | 1 | hallie | 106 | murhur de derpity derp | | 2 | dylan | 107 | banana spaghetti squid | | 4 | dominic | 108 | chicken |
Comments
Post a Comment