0

I have a visits and a ads table. I need every match from the visits table where the visits.aid = ads.id where the ads.uid=1. The actually query works, but I get everytime only 1 row from the visits table back and I need every selected row not just only one.

SELECT a.* FROM visits a INNER JOIN ads b ON a.aid = b.id WHERE b.uid = '1'
R2D2
  • 743
  • 1
  • 7
  • 14
  • 2
    You need every row from the `visits` table and only the rows from `ads` table that match the `visits` table on `visits.aid = ads.id and ads.uid = 1`? – nhgrif May 01 '15 at 23:22
  • I need every match from the visits table where the visits.aid = ads.id where the ads.uid=1 – R2D2 May 01 '15 at 23:30
  • 1
    Please update the question to include the actual values in both tables as well as the exact results you expect. – nhgrif May 01 '15 at 23:32
  • I just built out some temp tables and ran your query using SSMS, and your query is doing exactly what you want it to do. More info would be helpful. Also, I noticed that you have b.uid = '1' and in your explaination you have ads.uid = 1. Maybe it's a datatype issue. – Rogala May 01 '15 at 23:56
  • Is this your schema? http://sqlfiddle.com/#!9/980db/1 – grepsedawk May 02 '15 at 00:09
  • The Query definitely selects multiple rows. – grepsedawk May 02 '15 at 00:13
  • What happens if you do `SELECT COUNT(*) FROM ads WHERE uid = '1'`? – grepsedawk May 02 '15 at 00:14
  • 1
    since you tagged this with PHP I'm assuming that you are trying to get the data via PHP. If that's the case then you've likely only fetched one row instead of all the rows. please post your associated PHP code. – Jonathan May 02 '15 at 01:47

0 Answers0