View Single Post

   
  #1 (permalink)  
Old 05-12-2008, 09:08 AM
Chuck Cheeze
 
Posts: n/a
Default Can someone help with my SQL statement, Part 2

I have 3 tables:

category_posts (no columns to select, but sorting recordset by
sortorder column)
post_titles (select multiple columns)
post_data (select multiple columns)

All three tables contain an entry_id column and there is one record
per table for any given entry id, so there is a row to fetch from each
table for any entry_id that exists.

I have a pre-existing list of entry_id's to pull from the tables, so
basically what I need is:

select some data from post_titles and some other data post_data with a
corresponding entry_id. This is easy to do with an inner join. what
I can't get working is that I need to sort these records by the
sortorder column in the category_posts table. Again, there is a
corresponding entry_id in that table for all the records we are trying
to get.

I tried this but its producing duplicate rows in the wrong order.

SELECT wt.entry_id, wt.title, wt.url_title, wd.field_id_42,
wd.field_id_43, wd.field_id_44, wd.field_id_45, field_id_46,
field_id_47, field_id_55, field_id_56, field_id_57, field_id_64,
field_id_65 FROM exp_category_posts ecp INNER JOIN exp_weblog_titles
wt ON ecp.entry_id = wt.entry_id INNER JOIN exp_weblog_data wd ON
ecp.entry_id = wd.entry_id WHERE wt.status = 'open' and wt.weblog_id =
'8' AND wt.entry_id = '1533' OR wt.entry_id = '1949' OR wt.entry_id =
'1531' OR wt.entry_id = '1392' OR wt.entry_id = '1389' OR wt.entry_id
= '1388' OR wt.entry_id = '1390' OR wt.entry_id = '1391' OR
wt.entry_id = '1185' OR wt.entry_id = '1186' OR wt.entry_id = '1361'
OR wt.entry_id = '1187' OR wt.entry_id = '1188' ORDER BY ecp.sortorder
asc

Thanks
Reply With Quote