{"action":"created","issue":{"url":"https://api.github.com/repos/jmoiron/sqlx/issues/131","labels_url":"https://api.github.com/repos/jmoiron/sqlx/issues/131/labels{/name}","comments_url":"https://api.github.com/repos/jmoiron/sqlx/issues/131/comments","events_url":"https://api.github.com/repos/jmoiron/sqlx/issues/131/events","html_url":"https://github.com/jmoiron/sqlx/issues/131","id":66777861,"number":131,"title":"better tools for join queries","user":{"login":"jmoiron","id":218132,"avatar_url":"https://avatars.githubusercontent.com/u/218132?v=3","gravatar_id":"","url":"https://api.github.com/users/jmoiron","html_url":"https://github.com/jmoiron","followers_url":"https://api.github.com/users/jmoiron/followers","following_url":"https://api.github.com/users/jmoiron/following{/other_user}","gists_url":"https://api.github.com/users/jmoiron/gists{/gist_id}","starred_url":"https://api.github.com/users/jmoiron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmoiron/subscriptions","organizations_url":"https://api.github.com/users/jmoiron/orgs","repos_url":"https://api.github.com/users/jmoiron/repos","events_url":"https://api.github.com/users/jmoiron/events{/privacy}","received_events_url":"https://api.github.com/users/jmoiron/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jmoiron/sqlx/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/jmoiron/sqlx/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2015-04-07T05:19:33Z","updated_at":"2015-10-23T13:11:22Z","closed_at":null,"body":"Having thought over `sqlx.In` and the way it interacts with `sqlx.BindNamed` for a while, I've started to also explore other ways that sqlx can help people with their queries.  Besides `IN` queries, one of the sticking points in SQL has been JOIN queries, especially when you've already \"modeled\" your tables appropriately.\r\n\r\n@andybons asked me in IRC today if there was any better way of dealing with joins, and I said no, because the info you get from `Columns()` doesn't include [fully qualified names](http://stackoverflow.com/questions/268296/have-mysql-select-statement-return-fully-qualified-column-names-like-table-field).  However, that's just for `SELECT *`;  obviously,   I think something like this should be possible:\r\n\r\n```go\r\ntype Person struct {\r\n    Name string\r\n}\r\n\r\ntype Place struct {\r\n    Name string\r\n}\r\n\r\n// ...\r\nfunc etc(db *sqlx.DB) {\r\n    var pp struct {\r\n        Person `db:\"person,prefix=person.\"`\r\n        Place  `db:\",prefix=place.\"` // uses default Mapper\r\n    }\r\n    \r\n    db.Get(&pp, `SELECT \r\n            person.name \"person.name\", \r\n            place.name \"place.name\" \r\n        FROM person, place LIMIT 1;`)\r\n}\r\n```\r\n\r\nYou could use `_` or some such so you wouldn't have to quote the names in the aliases as well.  If the repetition is bothersome, you could always:\r\n\r\n```go\r\nfunc qualify(name string) string {\r\n    return fmt.Sprintf(`%v \"%v\"`, name, name)\r\n}\r\n```\r\n\r\nOr even a simple parser similar to how `sqlx.In` and `sqlx.BindNamed` work:\r\n\r\n```\r\nquery := qualify(\"SELECT q:person.name, q:place.name FROM person, place;\")\r\n```\r\n\r\nThe actual missing piece is a way to tell sqlx that an embedded struct should provide a prefix for its members.  I have to think this out a bit more;  the straightforward uses of this seem pretty useful, but multiple levels of prefixed embeds sounds complex and confusing.\r\n"},"comment":{"url":"https://api.github.com/repos/jmoiron/sqlx/issues/comments/150567045","html_url":"https://github.com/jmoiron/sqlx/issues/131#issuecomment-150567045","issue_url":"https://api.github.com/repos/jmoiron/sqlx/issues/131","id":150567045,"user":{"login":"pkieltyka","id":18831,"avatar_url":"https://avatars.githubusercontent.com/u/18831?v=3","gravatar_id":"","url":"https://api.github.com/users/pkieltyka","html_url":"https://github.com/pkieltyka","followers_url":"https://api.github.com/users/pkieltyka/followers","following_url":"https://api.github.com/users/pkieltyka/following{/other_user}","gists_url":"https://api.github.com/users/pkieltyka/gists{/gist_id}","starred_url":"https://api.github.com/users/pkieltyka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pkieltyka/subscriptions","organizations_url":"https://api.github.com/users/pkieltyka/orgs","repos_url":"https://api.github.com/users/pkieltyka/repos","events_url":"https://api.github.com/users/pkieltyka/events{/privacy}","received_events_url":"https://api.github.com/users/pkieltyka/received_events","type":"User","site_admin":false},"created_at":"2015-10-23T13:11:22Z","updated_at":"2015-10-23T13:11:22Z","body":"hmm.. I feel we should close this since and open more specific ideas for how to improve Join further. @nubbel most of the functionality discussed above has been merged for a few months now"}}