Why does my db query return zero(no data) in the required coloumns

Prog_Rookie

im trying to write a database query to populate two coloumns of a custom table of myn by using three other tables in the same db, but currently those coloumns return nothing, i will provide tables and my query below!!! can any body solve this problem

table_17

trackID MyID    Rid     panelID timestamp           useragent_browser   useragent_OS
1       17      123     25      2014-04-29 10:02:01 Default Browser     unknown NULL
2       17      123     25      2014-04-30 05:11:01 Default Browser     unknown NULL
3       17      123     25      2014-05-15 06:44:02 Default Browser     unknown NULL
4       17      59595   25      2014-10-06 07:50:30 Default Browser     unknown 0
5       17      59595   25      2014-10-06 07:51:29 NULL    NULL        0
6       17      59595   25      2014-10-06 07:54:51 NULL    NULL        0
7       17      789     25      2014-10-07 10:20:29 Default Browser     unknown 0
8       17      789     25      2014-10-07 10:23:48 Default Browser     unknown 0
9       17      1881    25      2014-10-27 05:16:11 NULL    NULL        0
10      17      188     25      2014-10-27 05:18:29 NULL    NULL        0

projects

MyID    projectname     accountID   creationdate        status  launchdate      closedate       total_impr
1       Virgo mobile        1       2010-07-07 09:09:09 3   2010-08-18 09:23:51 2011-11-18 19:38:41 1999
2       sys test            1       2010-06-05 09:12:35 3   2010-06-16 09:10:33 2010-06-30 11:23:55 2
16      test2               1       2010-08-16 14:12:50 1   NULL            NULL            0
7       testproject         1       2010-08-24 14:44:40 2   2014-03-21 22:55:46 NULL            27
18      system2             1       2010-09-21 13:57:46 2   2010-09-21 12:03:23 NULL            51529
19      Holidayland         1       2010-09-30 08:36:55 2   2010-10-03 09:23:55 NULL            6246491
20      thor_test           1       2010-11-17 17:41:11 2   2014-07-17 10:43:53 NULL            0
21      cima                1       2011-02-14 19:13:32 2   2014-07-17 05:07:40 NULL            0

my query

mysql_query("
INSERT INTO custom_table (`useragent_browser`, `useragent_OS`,`MyID`,`timestamp`,`projectname`)
SELECT `useragent_browser`, `useragent_OS`, 'b.timestamp', 'b.MyID',`projectname`
FROM $table a, projects b
WHERE a.timestamp > DATE_ADD(NOW(), INTERVAL -1 MONTH) AND a.MyID = b.MyID") 
or die(mysql_error());

The result i get from the query

trackID projectname MyID    Rid     panelID timestamp       useragent_browser   useragent_Os

1       testproject 0       NULL    25  0000-00-00 00:00:00 NULL    NULL        NULL
2       testproject 0       NULL    25  0000-00-00 00:00:00 NULL    NULL        NULL
4       Test168-150 0       NULL    25  0000-00-00 00:00:00 Chrome  Win7        NULL
5       Test168-150 0       NULL    25  0000-00-00 00:00:00 Chrome  Win7        NULL
6       Test168-150 0       NULL    25  0000-00-00 00:00:00 Default Browser     unknown NULL
7       Test-155    0       NULL    25  0000-00-00 00:00:00 Default Browser     unknown NULL
8       Test-155    0       NULL    25  0000-00-00 00:00:00 Default Browser     unknown NULL
9       Test-155    0       NULL    25  0000-00-00 00:00:00 Default Browser     unknown NULL
10      Test-155    0       NULL    25  0000-00-00 00:00:00 Default Browser     unknown NULL
14      test155     0       NULL    25  0000-00-00 00:00:00 Default Browser     unknown NULL

The columns which i need to populate Myid and timestamp is zero.. can anybody help me to populate those two correctly

Edit: organized query for readability above

Devon

You are accessing them incorrectly (as strings) and you have them reversed.

In the INSERT you have:

`MyID`,`timestamp`

In the SELECT you have:

'b.timestamp', 'b.MyID'

It should be:

`b.MyID`, `b.timestamp`

Therefore you are not using quotes, so they are not evaluated as strings and they are in the correct order.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why does Laravel return a Db::table query as string(5) "Sally"

From Java

Why does my DNS MX query return an SOA record?

From Dev

Why does CodeIgniter return my SQL query as an array, with an object inside?

From Dev

Why does my Firebase query return the wrong order?

From Dev

Why does my mysql query always return an empty result?

From Dev

Why does my LINQ query always return 0?

From Dev

Why does my SQL query return no rows, when sum is 0

From Dev

Why does my function not return the data I expect?

From Dev

Why does this query return no results?

From Dev

Why does this query return no results?

From Dev

Why does this Query return NULL?

From Dev

Why does my API return {}

From Dev

What does Zend Db Query return on failure?

From Dev

Why does my query return no records inside a program (PL/SQL), but does when ran manually in SQL?

From Dev

Why does my query return no records inside a program (PL/SQL), but does when ran manually in SQL?

From Dev

Why does my SQL query != "Some Value" not return any rows where NULL?

From Dev

Why does my SPARQL query return the URI of a resource instead of its name?

From Dev

My query to retrieve events between 2 search dates does not return any results, why?

From Dev

Why does my SQL query != "Some Value" not return any rows where NULL?

From Dev

Beginner hibernate: Why does my hibernate query return only one result, instead of a list?

From Dev

Why return is required while defining my module using requirejs?

From Dev

Why exactly does this Lucene query return no hits?

From Java

Why does a GraphQL query return null?

From Dev

Why does not this DL query return expected results?

From Dev

Why does this dapper query return null?

From Dev

Why does this query return unwanted rows

From Dev

Why does this MySQL XOR query return 0?

From Dev

Why does this query always return ALL records?

From Dev

<> or NOT IN, and why does query return wrong results

Related Related

  1. 1

    Why does Laravel return a Db::table query as string(5) "Sally"

  2. 2

    Why does my DNS MX query return an SOA record?

  3. 3

    Why does CodeIgniter return my SQL query as an array, with an object inside?

  4. 4

    Why does my Firebase query return the wrong order?

  5. 5

    Why does my mysql query always return an empty result?

  6. 6

    Why does my LINQ query always return 0?

  7. 7

    Why does my SQL query return no rows, when sum is 0

  8. 8

    Why does my function not return the data I expect?

  9. 9

    Why does this query return no results?

  10. 10

    Why does this query return no results?

  11. 11

    Why does this Query return NULL?

  12. 12

    Why does my API return {}

  13. 13

    What does Zend Db Query return on failure?

  14. 14

    Why does my query return no records inside a program (PL/SQL), but does when ran manually in SQL?

  15. 15

    Why does my query return no records inside a program (PL/SQL), but does when ran manually in SQL?

  16. 16

    Why does my SQL query != "Some Value" not return any rows where NULL?

  17. 17

    Why does my SPARQL query return the URI of a resource instead of its name?

  18. 18

    My query to retrieve events between 2 search dates does not return any results, why?

  19. 19

    Why does my SQL query != "Some Value" not return any rows where NULL?

  20. 20

    Beginner hibernate: Why does my hibernate query return only one result, instead of a list?

  21. 21

    Why return is required while defining my module using requirejs?

  22. 22

    Why exactly does this Lucene query return no hits?

  23. 23

    Why does a GraphQL query return null?

  24. 24

    Why does not this DL query return expected results?

  25. 25

    Why does this dapper query return null?

  26. 26

    Why does this query return unwanted rows

  27. 27

    Why does this MySQL XOR query return 0?

  28. 28

    Why does this query always return ALL records?

  29. 29

    <> or NOT IN, and why does query return wrong results

HotTag

Archive