Jump to content

Join Query - sorry for this simple question


BillWestman

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.