Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Need help with a SQL query (threads + newest post all-in-one)

netgertnetgert Member Posts: 331
Let's say I have 2 basic tables with these columns:
t1: id INT, cat INT
t2: id INT, thread INT, time INT
The t1.cat is given (ie "WHERE t1.cat = '1'")
Now I need to get all rows where t1.cat = '1' and with that row, also pick the row with the highest 'time' from t2 where t2.thread = t1.id
I've tried using complex subqueried and joins but so far I've got everything except what I need

Note: data in t1 and t2 are actually contained in one table but "threads" are split from "replies" and one of the results is put into temporary table, otherwise I will compare table.id = table.cat and that won't work
[hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

Comments

  • netgertnetgert Member Posts: 331
    i solved it in 3 querys...

    : Let's say I have 2 basic tables with these columns:
    : t1: id INT, cat INT
    : t2: id INT, thread INT, time INT
    : The t1.cat is given (ie "WHERE t1.cat = '1'")
    : Now I need to get all rows where t1.cat = '1' and with that row, also pick the row with the highest 'time' from t2 where t2.thread = t1.id
    : I've tried using complex subqueried and joins but so far I've got everything except what I need
    :
    : Note: data in t1 and t2 are actually contained in one table but "threads" are split from "replies" and one of the results is put into temporary table, otherwise I will compare table.id = table.cat and that won't work
    : [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]
    :

    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

Sign In or Register to comment.