Question: I have a table that is similar below.

```
     |  user_id  |   point_1  | point_2  | point_3
        453123        1234         32       433
        321543         1           213      321

```

My query is something like this: 

```
$query = "SELECT * FROM my_table WHERE user_id = 12345 OR user_id = 987654321"

```

Obviously, this will return nothing since `user_id` 12345 OR `user_id` 987654321 do not exist on the table.

But I still want to return something like the one below :

```
|  user_id   |   point_1  | point_2  | point_3
    12345           0           0         0
  987654321         0           0         0

```

Answer: 
You could use an inline view as a rowsource for your query. To return a zero in place of a NULL (which would be returned by the outer join when no matching row is found in my\_table, you can use the `IFNULL` function.

e.g.

```
SELECT s.user_id
     , IFNULL(t.point_1,0) AS point_1
     , IFNULL(t.point_2,0) AS point_2
     , IFNULL(t.point_3,0) AS point_3
  FROM ( SELECT 12345 AS user_id
         UNION ALL SELECT 987654321
       ) s
  LEFT
  JOIN my_table t
    ON t.user_id = s.user_id

```

NOTE: If datatype of `user_id` column my\_table is character, then I'd enclose the literals in the inline view in single quotes. e.g. **`SELECT '12345' AS user_id`**. If the characterset of the column doesn't match your client characterset, e.g. database column is latin1, and client characterset is UTF8, you'd want to force the character strings to be a compatible (coercible) characterset... **`SELECT _latin1'12345' AS user_id`**
Your desired result resembles the result of an `OUTER JOIN` - when some records exist only in one table and not the other, an `OUTER JOIN` will show all of the rows from one of the joined tables, filling in missing fields from the other table with `NULL` values.

To solve your particular problem purely in SQL, you could create a second table that contains a single field with all of the `user_id` values that you want to be able to show in your result. Something like:

```
+-----------+
| user_id   |
+-----------+
| 1         |
+-----------+
| 2         |
+-----------+
| 3         |
+-----------+
| ...       |
+-----------+
| 12344     |
+-----------+
| 12345     |
+-----------+
| 12346     |
+-----------+
| ...       |
+-----------+

```

And so on. If this second table is named `all_ids`, you could then get your desired result by modifying your query as follows (exact syntax may vary by database implementation):

```
SELECT
    *
FROM
    all_ids AS i
        LEFT OUTER JOIN
    my_table AS t ON i.user_id = t.user_id
WHERE
    i.user_id = 12345 
        OR i.user_id = 987654321;

```

This should produce the following result set:

```
+-----------+----------+----------+----------+
| user_id   | point_1  | point_2  | point_3  |
+-----------+----------+----------+----------+
| 12345     | NULL     | NULL     | NULL     |
+-----------+----------+----------+----------+
| 987654321 | NULL     | NULL     | NULL     |
+-----------+----------+----------+----------+

```

It should be noted that this table full of IDs could take up a significant amount of disk space. An [integer column in MySQL can hold 4,294,967,296 4-byte values](http://dev.mysql.com/doc/refman/5.0/en/integer-types.html), or 16 GB of data sitting around purely for your convenience in displaying some other data you *don't* have. So unless you need some smaller range or set of IDs available, or have disk space coming out your ears, this approach simply may not be practical.

Personally, I would not ask the database to do this in the first place. Essentially it's a display issue; you already get all the *information* you need from the fact that certain rows were *not* returned by your query. I would solve the display issue outside of the database, which in your case means filling in those zeroes with PHP.