Sql query help for a newbie

I have this query now that works, but I need a bit more data out.

SELECT * FROM wp_links INNER JOIN wp_toplist ON wp_links.link_id=wp_toplist.link_id ORDER BY TotalVotes DESC

Is there a way I can sum the wp_toplist.site_votes too ? like sum(site_votes) where site_id = $id ?

(well the order by part dont work cause I forgot to remove it after messing with the query with no luck)
Hope someone can help :smile:

[quote=“blackhat, post:1, topic:114146”]Is there a way I can sum the wp_toplist.site_votes too ? like sum(site_votes) where site_id = $id ?[/quote]could you please take a moment and explain exactly which columns you want to return in the query from each table

that dreaded, evil “select star” is messing up my understanding of what you want

Well I just used the star cause I was just lazy to write more :slight_smile: but this is what I come up with that worked

SELECT *, count(wp_toplist.link_id) AS totalVotes  FROM wp_toplist INNER JOIN wp_links ON wp_toplist.link_id=wp_links.link_id GROUP BY wp_toplist.link_id ORDER BY totalVotes DESC

One table contains the link information etc and the other (wp_toplist) takes care of the votes. I guess I could optimize it and remove the star :slight_smile:

if you’re gonna persist in using the dreaded, evil “select star” along with GROUP BY, please be aware that the values of some of the columns might be misleading

1 Like

so I should instead replace it with each of the fields I need from the table ?

that’d be a start ;o)

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.