![]() |
[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* |
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? |
Quote:
|
Now, I'm probably wrong, but don't you want to use a join statement in there at least once.
I think you need to link the tables to each other because I don't see how they are getting linked. Sorry I'm not that great of a db person. |
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 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. |
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. |
All times are GMT -8. The time now is 09:40 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project