Hi,
I am trying to compose a sql statement, a the moment i have this:
and it works a treatCode:SELECT user.username, user.outcode, item.ts_added, item.image, item.details, item.title, user.showlocation, postcodes.Latitude, postcodes.Longitude, item.thumb, FROM item LEFT JOIN user ON item.user_id = user.user_id LEFT JOIN postcodes ON postcodes.outcode = user.outcode WHERE item.item_id =57
what i also need to do is run a select count on another table that is related.
This table is called `given` and there are three fields
the item number in question (given.item_id) which is largely irrelevant to this particular query
and the user id of the receiver and the giver (given.user_idrec) and (given.user_idgiv)
and what i want to do is from the first query, find out how many times that user appears against a giver and a receiver,
I've tried all sorts of things and the most sucess i have had is with a subquery but this only works on one or the other (due to the ON clause joining the table)
I do hope this makes sense and that someone out there knows how i should go about this, i have a book on sql on order from amazon but its taking forever and i need this for my dissy project.
Many Thanks in advance, chrissie
oh and this is my code that doesnt quite do what i want... so you can see what i've been trying, this only gives me the count on whatever is named in the ON clause
Code:SELECT user.username, user.outcode, item.ts_added, item.image, item.details, item.title, user.showlocation, postcodes.Latitude, postcodes.Longitude, item.thumb, COUNT( given.user_idgiv ) AS giventimes, COUNT( given.user_idrec ) AS receivedtimes FROM item LEFT JOIN user ON item.user_id = user.user_id LEFT JOIN postcodes ON postcodes.outcode = user.outcode LEFT JOIN given ON given.user_idrec = user.user_id WHERE item.item_id =57 LIMIT 0 , 30




Bookmarks