Can I do this in mySQL? Or needs to be PHP?
| From: | Boget, Chris | Date: | Thu, 06 Jul 2000 15:19:20 +0000 |
| Subject: | Can I do this in mySQL? Or needs to be PHP? | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-902@lists.php.net to get a copy of this message | ||
First let me say that I'm unsure if this is the right
forum for this question. My apologies if it is not.
One of the few things that I dislike about mySQL
is that it cannot do sub-selects. I know you can
get around this somewhat by using JOINS, but I
am unfamiliar with anything but a basic JOIN.
There is a query that I need to run and I'm wonding
if someone can tell me if it is possible using mySQL
or if I'm going to have to work around it with PHP
code.
Here are the relevant tables and fields:
(main table)
table1
-> thing_name
(subordinate tables)
table2
-> thing_name
-> thing_type
table3
-> thing_name
-> thing_rarity
The field "thing_name" is the key in each field and
means the same in each. However, there will be
records in table1 that have a relational record in
table2 but not in table3. There can also be instances
wehre there'll be a record in table1 where there is
a relational record in table3 but not in table 2.
What I need to do is select records in all 3 tables to
get the relevant data. I'm not sure if I've made
myself overly clear, so here is the query that I've
been working with (which isn't working right):
SELECT user_haves.card_name FROM user_haves
LEFT JOIN cards_crypt ON user_haves.card_name = cards_crypt.name
AND cards_crypt.clan IN ( "Brujah", "Caitiff", "Gangrel",
"Giovanni" ) AND
cards_crypt.release_set IN ( "A", "JV", "V" )
LEFT JOIN cards_library ON user_haves.card_name = cards_library.name AND
cards_library.type IN ( "Action" ) AND cards_library.rarity IN ( "Rare" )
WHERE user_haves.user = "joebobbriggs"
ORDER BY cards_crypt.capacity, cards_crypt.clan, cards_library.type,
cards_library.requires, cards_library.rarity
The above query runs, but it doesn't return the correct
data. As I said, I'm pretty unfamiliar with JOINS so
please don't laugh if the above is blatently incorrect. :p
I know I can do what I need to do in PHP by just
selecting all the records and filtering the data, but I'm
hoping I can do this in mySQL so not only would it
be faster, but so I can learn something new. :P
Thanks for any help anyone can give.
Chris