![]() |
![]() |
#1 (permalink) |
Huggles, sir?
Location: Seattle
|
[MySQL] My brain blew a fuse (multi-table select, joins)
I had a brain fart and posted this in the Computer forum by mistake. Here it is, again, in the correct forum:
Hi! So, I'm working on a secret project thing which involves one record needing to be selected, along with info from a few other tables. The base record, "enhancement" needs to grab the origin(s) from the origin table, using the enhancement/origin join table, as well as effect(s) from the effect table, using the enhancement/effect join table, and finally, the server using the server_id and server table. I want this: Enhancement table values Origin(s) - from the origin table Server - from the server table Effect(s) - from the effect table Schemas: Code:
*yoink* Here's my query right now: Code:
*yoink* Code:
*yoink* ..and my query results: Code:
*yoink*
__________________
seretogis - sieg heil perfect little dream the kind that hurts the most, forgot how it feels well almost no one to blame always the same, open my eyes wake up in flames Last edited by seretogis; 05-20-2004 at 05:59 AM.. |
![]() |
![]() |
#2 (permalink) |
Pure Chewing Satisfaction
Location: can i use bbcode [i]here[/i]?
|
A shot in the dark...
isn't the GROUP BY command lumping all the records together that have the same enhancement_id? If that's the case, then all the results are merged into that one record being returned... do you mean to have ORDER BY? EDIT: or maybe you need to be more specific on *which* enhancement_id you want to group by?
__________________
Greetings and salutations. Last edited by Moskie; 05-17-2004 at 02:52 AM.. |
![]() |
![]() |
#3 (permalink) | |
Huggles, sir?
Location: Seattle
|
Quote:
![]()
__________________
seretogis - sieg heil perfect little dream the kind that hurts the most, forgot how it feels well almost no one to blame always the same, open my eyes wake up in flames |
|
![]() |
![]() |
#5 (permalink) |
Tilted
|
Not sure about the MySQL syntax. Too lazy to test. Caveat emptor.
I'm surprised MySQL lets you do that GROUP BY, since you don't have aggregate functions on the other columns. Maybe it automatically just uses the first or something. Anyways. Code:
SELECT e.*, o.origin, s.name, f.effect FROM coh_enhancement as e, coh_origin as o, coh_server as s, coh_enhancement_effect as f, coh_enhancement_effect_join as fj, coh_enhancement_origin_join as oj WHERE e.enhancement_id = fj.enhancement_id AND fj.effect_id = f.effect_id AND e.enhancement_id = oj.enhancement_id AND oj.origin_id = o.origin_id AND e.server_id = s.server_id Note also that those are most likely inner joins, so if there's no matching data in one of the tables, you won't get any rows back. Can't recall the syntax for a left join in MySQL. |
![]() |
![]() |
#6 (permalink) | |
Huggles, sir?
Location: Seattle
|
Quote:
![]() This doesn't do exactly what I was looking for, but I think that I am just trying to cram too much into one select -- I'll use your query and then do a little data massaging with PHP. Thanks again.
__________________
seretogis - sieg heil perfect little dream the kind that hurts the most, forgot how it feels well almost no one to blame always the same, open my eyes wake up in flames |
|
![]() |
Tags |
blew, brain, fuse, joins, multitable, mysql, select |
|
|