多对多关系查询

I'm a bit confused about many to many relationship tables, and the code that goes with them.

I have table1:

id, username

And table2:

id, votes_up, votes_down

And a helper table (htable):

vu, vd, adsid

What I want to happen is, when an ad is voted up or down, this vote doesn't go to all adverts.

My attempt at selecting data:

mysql_query("SELECT * 
             FROM dbo.tab2 
             INNER JOIN dbo.htable 
             WHERE tab2.votes_up = htable.vu 
                AND htable.votes_down = htable.vd 
             INNER JOIN dbo.tab1 
             WHERE htable.adsID = table1.ID");

And my insert attempt:

mysql_query("INSERT INTO dbo.htable (vu, vd, adsid)  
             VALUES 
             (SELECT FROM dbo.tab2.votes_up, dbo.tab2.votes_down , dbo.tab1.id)");

My question: Are these two queries correct? If not, how can I fix them? and what is the update query ?

I do not really understand your question, but your SQL queries are wrong. They should probably be something like:

SELECT
    *
FROM
    dbo.tab2 as tab2
    INNER JOIN dbo.htable as htable
        ON tab2.votes_up = htable.vu
        AND tab2.votes_down = htable.vd
    INNER JOIN dbo.tab1 as tab1
        ON htable.adsID = tab1.ID

and

INSERT INTO dbo.htable (vu, vd, adsID)
    SELECT
        votes_up, votes_down, ID
    FROM
        dbo.tab2