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
https://forums.phpfreaks.com/topic/81154-rows-from-2-tables/
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
https://forums.phpfreaks.com/topic/81154-rows-from-2-tables/#findComment-416320
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.