Say I have these 2 tables:
posts
id | user_id | title | slug | content | views
----+---------+-------+------+---------+-------
users
id | username | email | hash | role | auth
----+----------+-------+------+------+------
With these two tables I want to do a SELECT * FROM posts ...
query and ultimately end up responding with something like this:
{[
{
"id": "1",
"user_id": "2",
"title": "Foo",
"slug": "foo",
"content": "bar",
"views": "0",
"user": {
"id": "2",
"username": "john",
"email": "john@smith.com",
"hash": "aeigh*£HAEGhoiaehg",
"role": "admin",
"auth": "aeg89hiae9g8hA*H£GA(*EHG"
}
}
]}
I'm pretty new to SQL, and patterns like this seem pretty common when using an ORM, so I'm wondering what steps I have to do to get a result like this using raw SQL.
Any idea?