-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
District Webmaster wrote: | I need to join table 1 to table 2 -- and then table 2 back to table 1 | -- in the same query. While I think this is possible, I am having | difficulty achieving it.
<snip>
| 1) has: file_id, file_title, file_type, file_etc. | 2) has: file_id, related_file_id
<snip>
| As best as I can describe, I need to get the following information about | a file: | | Get the file_id and other info, as well as relationships it has with | other files -- and the file_id and other info about the related files. | | Under the current table structure, I need to join table a to table b to | table a. I would prefer to do this in one query. I _can_ change the | table layout if necessary.
In MySQL (and AFAIK, SQL in general) you can specify a table multiple times. So for your problem the following should work fine:
~ select f1.*, f2.* from file f1, file_relation r, file f2 ~ where f1.file_id=? and r.file_id=f1.file_id and ~ f2.file_id=r.related_file_id
(I've taken the liberty of naming the tables: file is table 1, file_relation is table 2.)
If for some reason this is insufficient, let us know why.
Jacob Fugal -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQFAIT0k/PO7QochUiQRAssCAJ9JROA2n+3AdOvnCQ+1lBBHXdS/mwCdGyEo g5bS1rUmnJL+h1SENW1GGTA= =Pd0V -----END PGP SIGNATURE-----
____________________
BYU Unix Users Group http://uug.byu.edu/ ___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list
