Jump to content

possible join query


jmag

Recommended Posts

Hello,

I believe this should be fairly simple, but I'm not quite sure how to do it.

I store some imagedata in a table and in another table I store which pages this image might be connected to. Lets see if I manage to put it on print:
All pictures that have pic_type right should be selected from the pics table and are connected to the current page being viewed.

the start of the query I came up with looks like this:
SELECT pic.*, conn.* FROM pics AS pic, pic_con AS conn WHERE pic.pic_type = 'right' AND conn.page_id = '1';
But there aren't any connection in that so I fetch the right rows from the pic_con, is it? well, beats me...

the table layouts look like this:
pics: pic_id, pic_src, pic_alt, pic_caption, pic_link, pic_type and pic_id is the primary key
pic_con: pic_id, page_id, page_sortorder where pic_id and page_id is a combined primary key

Greatful for any help!

[i]Edit:[/i]
I actually made the query work... forgot the from clause. But it returns the data a bit wrong. I get one pic_id from the pics table and on the same row another pic_id is returned from the pic_con table.
It would also be great if I in the same query get a random row from the result, so in the end only one row is returned.
Link to comment
https://forums.phpfreaks.com/topic/5848-possible-join-query/
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.