This is the query that I am using to match up a members name to an id.
SELECT eve_member_list.`characterID` ,eve_member_list.`name`
FROM `eve_mining_op_members`
INNER JOIN eve_member_list ON eve_mining_op_members.characterID = eve_member_list.characterID
WHERE op_id = '20110821105414-741653460';
My issue is that I have two different member lists, one lists are members that belong to our group and the second list is a list of members that do not belong to our group.
How do i write this query so that if a member is not found in the eve_member_list table it will look in the eve_nonmember_member_list table to match the eve_mining_op_members.characterID to the charName
I apologize in advance if the question is hard to read as I am not quite sure how to properly ask what it is that I am looking for.
Change your
INNER JOINto aLEFT JOINand join with both the tables. UseIFNULLto select the name if it appears in the first table, but if it isNULL(because no match was found) then it will use the value found from the second table.If you have control of the database design you should also consider if it is possible to redesign your database so that both members and non-members are stored in the same table. You could for example use a boolean to specify whether or not they are members. Or you could create a
persontable and have information that is only relevant to members stored in a separatememberinfotable with an nullable foreign key from thepersontable to thememberinfotable. This will make queries relating to both members and non-members easier to write and perform better.