BillWestman Posted February 9, 2011 Share Posted February 9, 2011 I have two tables with IDs (millions) - probably this is simple but I can not figure it out. (thank you in advance!) table 1 id 1 2 3 4 55 table 2 id 1 2 3 4 5 6 what I would like is a query that returns all of the matched and the unmatched Ids in ONE ROW table 3 id 1 2 3 4 5 6 55 *** Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/227119-join-query-sorry-for-this-simple-question/ Share on other sites More sharing options...
ale8oneboy Posted February 9, 2011 Share Posted February 9, 2011 Can you give us an example of how you would like to display the output as an result? Quote Link to comment https://forums.phpfreaks.com/topic/227119-join-query-sorry-for-this-simple-question/#findComment-1171767 Share on other sites More sharing options...
BillWestman Posted February 9, 2011 Author Share Posted February 9, 2011 Yes - like Table 3 Quote Link to comment https://forums.phpfreaks.com/topic/227119-join-query-sorry-for-this-simple-question/#findComment-1171901 Share on other sites More sharing options...
ale8oneboy Posted February 9, 2011 Share Posted February 9, 2011 Sorry, I must have not been paying attention this morning. You could create two select queries and use a UNION, then group by the ID field. This would give you a unique list of all ids from both tables match or non-matching. Example: SELECT * FROM ( (SELECT ID FROM TABLE_A) AS A UNION (SELECT ID FROM TABLE_B) AS B ) GROUP BY ID May not be the best query. But it would work. Quote Link to comment https://forums.phpfreaks.com/topic/227119-join-query-sorry-for-this-simple-question/#findComment-1171927 Share on other sites More sharing options...
ppwalks Posted February 10, 2011 Share Posted February 10, 2011 Hello, I was wondering if anyone could help solve this minor problem also, (sorry for interupting) I have an SQL statement as shown below; UPDATE cms SET metaName = '.$metaKey.', metaDesc = '.$metaDesc.' WHERE rowID = 1"; It updates the intended field when posted, but if a blank field is sent it overwrites the data with nothing, I want it so if blank basically do nothing and leave previous data in tact. Any help is much appreciated and thankyou for your time. Quote Link to comment https://forums.phpfreaks.com/topic/227119-join-query-sorry-for-this-simple-question/#findComment-1172234 Share on other sites More sharing options...
ale8oneboy Posted February 10, 2011 Share Posted February 10, 2011 Hello, I was wondering if anyone could help solve this minor problem also, (sorry for interupting) I have an SQL statement as shown below; UPDATE cms SET metaName = '.$metaKey.', metaDesc = '.$metaDesc.' WHERE rowID = 1"; It updates the intended field when posted, but if a blank field is sent it overwrites the data with nothing, I want it so if blank basically do nothing and leave previous data in tact. Any help is much appreciated and thankyou for your time. The simple answer to your problem is not to add that field in your update query. All the server knows to do with that statement is update the field to whatever you give it. If you're creating this query in a script (PHP for example), you could control what fields get updated based on if variable is NULL or Empty. Example: If you wanted to leave the data unchanged for the field metaDesc. You would change or have your script change the query to the following. UPDATE cms SET metaName = '$metaKey' WHERE rowID = 1 I would look into writing the script to check to see if the variables are empty before including them in the query. You could build it to where it dynamically builds the query before executing it. Quote Link to comment https://forums.phpfreaks.com/topic/227119-join-query-sorry-for-this-simple-question/#findComment-1172249 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.