-2
'SELECT * FROM (SELECT * FROM t1
          RIGHT OUTER JOIN t2 ON t1.wid = t2.wid
          WHERE t2.wid IS NULL)
          LIMIT ' . $number;

This SQL lines do not give not one row back and I do not know the reason. The t1 is full of rows while the t2 is an empty table.

halfer
  • 19,824
  • 17
  • 99
  • 186
Karmen
  • 238
  • 2
  • 15
  • Because you are doing `Right outer join` with no data in that table. If you want to get the all the rows from table1 then do the `Left outer Join`. – Mahesh Apr 01 '15 at 08:11
  • I must do left? With left it also not working – Karmen Apr 01 '15 at 08:12

1 Answers1

0

Given that you need to do a LEFT OUTER JOIN to retrieve the rows in t1

You will also need to avoid duplicate column names in the inner result before you make the outer select, eg SELECT t1.*

Also you may need to give an alias to the derived table in the inner select eg t3 ...

SELECT t3.* FROM (
    SELECT t1.* FROM t1
    LEFT OUTER JOIN t2 ON t1.wid = t2.wid
    WHERE t2.wid IS NULL)
AS t3;
Gavin Jackson
  • 1,907
  • 1
  • 22
  • 28
  • t3 is an arbitrary table alias given to the results of the inner select, it is then used to reference the intermediate results by the outer select. – Gavin Jackson Apr 01 '15 at 08:45