Jump to content

Rows from 2 tables


jaymc

Recommended Posts

I am familiar with using JOIN to join fields onto a row

 

However, I want something a little different, not sure if it can be done

 

I have 2 tables, one has image comments and another has profile comments

 

In 1 query, I want to pull in the last 10 profile comments and last 10 image comments. Virtually, I would have 20 rows in a temp table, I would then like to order them and display the last 10 posted

 

Of course I can do the last bit, its just getting the 20 rows together in 1 query. Can it be done?

Link to comment
Share on other sites

Ok I had a go at this and Its not doing what I want, just need to know if its the rules of UNION

 

I have 2 tables

 

1 holds profile comments

1 holds image comments

 

 

Both tables have similar fields, howeverm, the image one has a field for the image ID, and the profile one does not, but that has a field for the IP address

 

I need to pull out the image ID from the image comments table, but it does not exist in the profile table.

 

Is this impossible to do?

 

It would be good to have the result fill the image ID field as NULL if it doesnt exist, that way if its NULL I know it must be a profile comment, if its not, it must be an IMAGE comment, which is precicesly what I want

 

Any ideas?

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.