SV: Need help with SELECT 2 tables from choice of 3
Can't you just make a check before you make a call to the DB? if( member_id 1000 ) // old member query here else // new member query here -Ursprungligt meddelande- Fran: Jerry [mailto:[EMAIL PROTECTED]] Skickat: den 21 november 2001 21:24 Till: [EMAIL PROTECTED] Amne: Re: Need help with SELECT 2 tables from choice of 3 Why no have 3 tables: Members Data TheseMembersAreOld Members and Data are as you have them defined. TheseMembersAreOld contains only the Member_ID field. You then make the Member_ID field primary key on TheseMembersAreOld and Members. You can then perform a very fast joins. Hm, thank you for the idea... I think my problem is the OLD members and members are not the same people. That is why I have renamed them (added 10 number to every one of them), so Data table now has numbers from 1-1000 (my new members) numbers from 10 to 101000 (my old members). From old members I only need the name, nothing else! From new members I need all the data. Now because in the forum topic (yes, I am builing a custom forum) there must be a member, I need 1. If this is an old member from the old forum to disply only name 2. If member is new to display all the data. Now I have a problem of joining the 3 tables because obviously in Data field Member_ID there is a number that represents a member OR a number that represents a old member, never both (none is the same). In SQL I can not do the AND and compare both MEMBER_ID's because it would never return anything. If I use or I do get data, but not one, but multiplied number od times (every new member is then resulted or every old member, depending on in which table SQL finds the data). Yours Jerry Slovenia - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
SV: Need help with SELECT 2 tables from choice of 3
You can join all three tables together select d.members_id, m.name, old.name from data as d left join members as m on m.members_id=d.members_id left join oldmembers as old on old.members_id=d.members_id If the members_id belongs to an old member, all fields from the member table will be null. If it's a new member, all fields from the old member table will be null .. That way you only need to query the database once. Then, in your PHP/ASP code you check if id 1000 and if it is you use the fields from the new members table... d.members_id, m.name, old.name 1 NULLname1 100 NULLname2 2000name2 NULL /torgil I left joined the DATA with MEMBERS and in a loop when displaying records, when I see that the MEMBER_ID belongs to the old member, I open another recordset that get's me his name from OLDMEMBERS table. I thought that this is better than the first solution because when my database grows, all of the new messages will be from new members, not old, so the condition to open recordset in for...next loop would not be executed. Is my thinking valid? Yours Jerry - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Need help with SELECT 2 tables from choice of 3
Hi there I need help :-)) If anybody could be so kind and help me... I have 3 tables: OldMembers Memebers Data In Data there is a field Member_ID. Now in this field all members bigger than 100.000 are old ones and must be taken from the OldMembers table (both tables are not using same data so I can not one from both). If Member_ID is smaller than 100.000 the data from Members is taken. I can not join all 3 tables because a member is either a member of Member or OldMember, never of both. I would need in mySQL query something like IF, but not to make a value of yes or no, but something like IF Member_ID 100.000 then ELSE ... I have 1000 records in Data table and I need to have Usernames either from one or from the second Member table. I can not do that... SQL doesn't seem to have such strong programming language to make complex sentance. I tried using IF and put a result string like part of SQL query, like AND MEMBER.MEMBER_ID = Data.Member_ID or AND OLDMEMBER.MEMBER_ID = Data.MEMBER_ID and the inserting the result (I called it thequery) into WHERE part but doesn't work... I am really stuck... The only way to think is: Simply take all 1000 records without join and inside a for...next loop in ASP look what the ID_MEMBER of record is and make SELECT statement inside this loop. Now I am not sure how efficient is this... Means every record from 1...1000 would open a new recordset from the members or oldmembers table. There must be another way directly from the SQL query. I looked everything on Internet about this problem and couldn't find any solution. Could you just point me to any direction, is this possible or not? Thank you a 1000 times... Yours Jerry Slovenia - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: Need help with SELECT 2 tables from choice of 3
OldMembers Memebers Data Why no have 3 tables: Members Data TheseMembersAreOld Members and Data are as you have them defined. TheseMembersAreOld contains only the Member_ID field. You then make the Member_ID field primary key on TheseMembersAreOld and Members. You can then perform a very fast joins. Thomas, Denmark - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: Need help with SELECT 2 tables from choice of 3
Why no have 3 tables: Members Data TheseMembersAreOld Members and Data are as you have them defined. TheseMembersAreOld contains only the Member_ID field. You then make the Member_ID field primary key on TheseMembersAreOld and Members. You can then perform a very fast joins. Hm, thank you for the idea... I think my problem is the OLD members and members are not the same people. That is why I have renamed them (added 10 number to every one of them), so Data table now has numbers from 1-1000 (my new members) numbers from 10 to 101000 (my old members). From old members I only need the name, nothing else! From new members I need all the data. Now because in the forum topic (yes, I am builing a custom forum) there must be a member, I need 1. If this is an old member from the old forum to disply only name 2. If member is new to display all the data. Now I have a problem of joining the 3 tables because obviously in Data field Member_ID there is a number that represents a member OR a number that represents a old member, never both (none is the same). In SQL I can not do the AND and compare both MEMBER_ID's because it would never return anything. If I use or I do get data, but not one, but multiplied number od times (every new member is then resulted or every old member, depending on in which table SQL finds the data). Yours Jerry Slovenia - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php