I'm trying to figure out why results returned via a MySQL terminal query don't match those returned by a MySQL query executed by PHP.
Here's the MySQL used in the shell:
SELECT * FROM SANKEY_NODE AS n
LEFT OUTER JOIN TYPE_DETAIL as td
ON n.TYPE_DETAIL_ID = td.TYPE_DETAIL_ID
LEFT OUTER JOIN GRAPH_TYPE as t
ON td.GRAPH_TYPE_ID = t.GRAPH_TYPE_ID
WHERE CHART_ID = 39;
Here's the PHP:
function get_nodes_by_chart_id($con, $chart_id) {
$sql = 'SELECT * FROM SANKEY_NODE AS n
LEFT OUTER JOIN TYPE_DETAIL as td
ON n.TYPE_DETAIL_ID = td.TYPE_DETAIL_ID
LEFT OUTER JOIN GRAPH_TYPE as t
ON td.GRAPH_TYPE_ID = t.GRAPH_TYPE_ID
WHERE CHART_ID = '.$chart_id.';';
$result = mysqli_query($con, $sql);
return results_to_array($result);
}
function results_to_array($results) {
$rows = array();
while($row = mysqli_fetch_assoc($results)) {
$rows[] = $row;
}
return $rows;
}
Both queries return a dozen results, however, they differ in their representation of three results. Those three results are special because they have a TYPE_DETAIL_ID value in the SANKEY_NODE table that is not present in the TYPE_DETAIL table.
In the MySQL shell, the TYPE_DETAIL_ID value for the three affected nodes is displayed, whereas in the results returned by PHP, the TYPE_DETAIL_ID value is null. Does anyone know what might cause this difference? I'd be very grateful for any insight others can offer!
Table Structures
mysql> describe SANKEY_NODE;
+----------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+-------+
| NODE_NAME | varchar(100) | NO | | NULL | |
| NODE_PARENT | varchar(20) | YES | | NULL | |
| CHART_ID | int(11) | NO | PRI | NULL | |
| NODE_TYPE | varchar(100) | NO | | NULL | |
| TYPE_DETAIL_ID | varchar(20) | NO | PRI | NULL | |
+----------------+--------------+------+-----+---------+-------+
mysql> describe TYPE_DETAIL;
+------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+-------+
| COMPANY_ID | int(11) | NO | | NULL | |
| GRAPH_TYPE_ID | int(11) | NO | PRI | NULL | |
| TYPE_DETAIL_CD | varchar(20) | NO | PRI | NULL | |
| TYPE_DETAIL_NAME | varchar(100) | NO | | NULL | |
| TYPE_DETAIL_DESC | varchar(200) | YES | | NULL | |
| TYPE_DETAIL_ID | int(11) | NO | | NULL | |
| TYPE_IMAGE_ID | int(11) | YES | | NULL | |
| ACTIVE_FLAG | bit(1) | NO | | NULL | |
+------------------+--------------+------+-----+---------+-------+
mysql> describe GRAPH_TYPE;
+----------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------------+--------------+------+-----+---------+----------------+
| COMPANY_ID | int(11) | NO | PRI | NULL | |
| GRAPH_TYPE_ID | int(11) | NO | UNI | NULL | auto_increment |
| TYPE_CD | varchar(20) | NO | PRI | NULL | |
| TYPE_NAME | varchar(100) | NO | | NULL | |
| TYPE_COLOR | varchar(50) | NO | | NULL | |
| TYPE_HIGHLIGHT_COLOR | varchar(50) | NO | | NULL | |
| ACTIVE_FLAG | bit(1) | NO | | NULL | |
+----------------------+--------------+------+-----+---------+----------------+
Comment Responses
#Cedric, running the query with just the first JOIN yields the same results. The three values whose TYPE_DETAIL_ID is present in SANKEY_NODE but not in TYPE_DETAIL_ID have a defined TYPE_DETAIL_ID in the shell results but not in the results via PHP (see results below). As for syntax, I'm a fan of the philosophy that "explicit is better than implicit".
#jcaron, the TYPE_DETAIL_ID values are either sequences of integers or ascii strings, e.g.:
mysql> SELECT * FROM SANKEY_NODE AS n LEFT OUTER JOIN TYPE_DETAIL as td ON n.TYPE_DETAIL_ID = td.TYPE_DETAIL_ID WHERE CHART_ID = 3;
+--------------------------+-------------+----------+-------------+----------------+------------+---------------+----------------+--------------------+--------------------+----------------+---------------+-------------+
| NODE_NAME | NODE_PARENT | CHART_ID | NODE_TYPE | TYPE_DETAIL_ID | COMPANY_ID | GRAPH_TYPE_ID | TYPE_DETAIL_CD | TYPE_DETAIL_NAME | TYPE_DETAIL_DESC | TYPE_DETAIL_ID | TYPE_IMAGE_ID | ACTIVE_FLAG |
+--------------------------+-------------+----------+-------------+----------------+------------+---------------+----------------+--------------------+--------------------+----------------+---------------+-------------+
| CRD | SYS | 3 | System | 101004 | 7777 | 1 | CRD | Charles River | Charles River | 101004 | NULL | |
| FactSet | SYS | 3 | System | 101012 | 7777 | 1 | FACTSET | Factset | Factset | 101012 | NULL | |
| MSCI | SYS | 3 | System | 101016 | 7777 | 1 | RISKMETRICS | MSCI RiskWorld | MSCI RiskWorld | 101016 | NULL | |
| Trade Execution | FUN | 3 | Function | 109007 | 7777 | 9 | TE | Trade Execution | Trade Execution | 109007 | NULL | |
| Portfolio Mgmt | FUN | 3 | Function | 109003 | 7777 | 9 | PM | Portfolio Mgmt | Portfolio Mgmt | 109003 | NULL | |
| Performance & Risk | FUN | 3 | Function | 109002 | 7777 | 9 | PMR | Performance & Risk | Performance & Risk | 109002 | NULL | |
| Operations | FUN | 3 | Function | 109006 | 7777 | 9 | OPS | Operations | Operations | 109006 | NULL | |
| Decision Making | FUN | 3 | Function | 109001 | 7777 | 9 | DM | Decision Making | Decision Making | 109001 | NULL | |
| Compliance | FUN | 3 | Function | 109005 | 7777 | 9 | COMP | Compliance | Compliance | 109005 | NULL | |
| Portfolio Rebalance | SFUN | 3 | SubFunction | 201091 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| Position Reconciliation | SFUN | 3 | SubFunction | 201092 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| PreTrade Compliance | SFUN | 3 | SubFunction | 201096 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| Step-outs | SFUN | 3 | SubFunction | 201109 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| Trade Matching | SFUN | 3 | SubFunction | 201125 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| Trade Settlement | SFUN | 3 | SubFunction | 201129 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| Functions | | 3 | Function | FUN | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| SubFunction | | 3 | SubFunction | SFUN | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| Systems | | 3 | System | SYS | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
+--------------------------+-------------+----------+-------------+----------------+------------+---------------+----------------+--------------------+--------------------+----------------+---------------+-------------+
18 rows in set, 225 warnings (0.00 sec)
Here is an easy workaround, specify the table name for each column :
SELECT SANKEY_NODE.TYPE_DETAIL_ID FROM SANKEY_NODE AS n
That way, you will be sure to have the data that you expect
Related
I have three tables
users table
+--------------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------------+--------------+------+-----+---------+----------------+
| Id | bigint | NO | PRI | NULL | auto_increment |
| AccountNumber | varchar(50) | YES | | NULL | |
| DisplayName | varchar(255) | YES | MUL | NULL | |
| ParentAccountId | bigint | YES | MUL | NULL | |
| AccountTypeRef | bigint | YES | MUL | NULL | |
| PhoneNo | varchar(255) | YES | | NULL | |
| FaxNo | varchar(50) | YES | | NULL | |
| Website | varchar(200) | YES | | NULL | |
| Email | varchar(100) | YES | | NULL | |
| StateRef | bigint | YES | MUL | NULL | |
| Address | longtext | YES | | NULL | |
| PostalCode | varchar(50) | YES | | NULL |
products table
+-------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------+------+-----+---------+----------------+
| Id | bigint | NO | PRI | NULL | auto_increment |
| ProductId | bigint | YES | MUL | NULL | |
| PackName | varchar(255) | YES | | NULL | | |
| Price | double | YES | | NULL | |
| OnlineInfoAddress | varchar(255) | YES | | NULL | |
| Description | longtext | YES | | NULL | |
| IsDelete | tinyint | YES | | NULL | |
| CreateUserId | bigint | YES | | NULL | |
| CreateDate | datetime | YES | | NULL | |
| EditDate | datetime | YES | | NULL | |
| EditUserId | bigint | YES | | NULL | |
| Tag | int | YES | | NULL | |
| Ref | varchar(50) | YES | | NULL | |
| deleted_at | timestamp | YES | | NULL | |
+-------------------+--------------+------+-----+---------+----------------+
users_buy table
+---------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+----------------+
| Id | bigint | NO | PRI | NULL | auto_increment |
| users_id | bigint | YES | MUL | NULL | |
| product_id | bigint | YES | MUL | NULL | |
| BuyDate | datetime | YES | | NULL | |
| CountBuy | int | YES | | NULL | |
| TotalPrice | double | YES | | NULL | |
| Description | longtext | YES | | NULL | |
| invoiceNumber | varchar(255) | YES | | NULL | |
+---------------+--------------+------+-----+---------+----------------+
I want to get users who did not buy a specific product
for example, user number 20 bought 5 product with ids [1,2,3,4,5]
and user number 19 bought 3 product with ids [1,2,3]
And user number 18 bought 2 product with ids [1,3]
I want to get users who did not buy any product with the id 5
ie I want user 18 and 19
How can I do this?
This will list of all users that did not buy product id 5:
SELECT *
FROM users
WHERE
Id NOT IN (
SELECT users_id
FROM users_buy
WHERE product_id = 5
)
One more solution used LEFT JOIN:
SELECT users.*
FROM users
LEFT JOIN users_buy
ON users_buy.users_id = users.id AND users_buy.product_id = 5
WHERE users_buy.user_id IS NULL;
The above query will return records from users table have not matched rows in users_buy table with product_id 5
I have two tables, users and lifts.
On my UI (php webpage), I have two drop downs (as well as others, irrelevant), one drop down is [userlastname, userfirstname], and the other is [destination]
the query i am using is this:
SELECT * FROM lifts l JOIN users u ON l.user_id=u.uid GROUP BY l.id;
which gives me the list of usernames in users (correctly)
[Harvey Fletcher]
[Ronald McDonald]
[Harvey Fletcher]
and also a list of all destinations
[Destination 1]
[Destination 2]
[Destination 3]
But as you can see from the usernames list, [Harvey Fletcher] has appeared twice. How can I stop this from happening? Table structure below.
Users:
+---------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+--------------+------+-----+---------+----------------+
| uid | int(10) | NO | PRI | NULL | auto_increment |
| title | varchar(10) | NO | | NULL | |
| firstname | varchar(100) | NO | | NULL | |
| lastname | varchar(100) | NO | | NULL | |
| email | varchar(500) | NO | | NULL | |
| password | varchar(500) | NO | | NULL | |
| reg_no | varchar(10) | YES | | NULL | |
| vehicle_make | varchar(50) | YES | | NULL | |
| vehicle_colour | varchar(25) | YES | | NULL | |
| licence_no | varchar(50) | YES | | NULL | |
| address_line1 | varchar(75) | NO | | NULL | |
| address_line2 | varchar(75) | NO | | NULL | |
| town_city | varchar(75) | NO | | NULL | |
| postcode | varchar(10) | NO | | NULL | |
| reputation_positive | int(10) | YES | | 0 | |
| reputation_negative | int(10) | YES | | 0 | |
| telephone_number | char(11) | NO | | NULL | |
+---------------------+--------------+------+-----+---------+----------------+
Lifts:
+-----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+----------------+
| id | int(10) | NO | PRI | NULL | auto_increment |
| user_id | int(10) | NO | | NULL | |
| lift_to | varchar(50) | NO | | NULL | |
| lift_from | varchar(50) | NO | | NULL | |
| quote_price | varchar(50) | NO | | NULL | |
| available_seats | int(2) | YES | | 1 | |
| depart_date | varchar(20) | NO | | NULL | |
| depart_time | varchar(10) | NO | | NULL | |
| pickup_location | varchar(100) | NO | | NULL | |
+-----------------+--------------+------+-----+---------+----------------+
Info:
Harvey Fletcher is only in users table once
Harvey Fletcher has two 'lifts', which is why it appears twice.
Ronald McDonald only has one, so only appears once, but if I added a second lift, would be displayed 2 times.
Group your query to users instead of lifts:
SELECT * FROM lifts l JOIN users u ON l.user_id=u.uid GROUP BY u.uid;
insert into `patient` ( `pat_f_name`, `pat_l_name`, `pat_gender`, `pat_age`, `pat_dob`, `pat_blood_grp`, `pat_weight`, `pat_contact_no`, `pat_address` )
-> VALUES
-> ('$user_fname','$user_lname','$user_gender','$user_age','$user_dob','$user_bg','$user_weight','$user_contact_no','$user_address');
ERROR 1366 (HY000): Incorrect integer value: '$user_age' for column 'pat_age' at row 1
the table looks like
+----------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+----------------+
| pat_id | int(50) | NO | PRI | NULL | auto_increment |
| dr_id | int(50) | NO | | NULL | |
| pat_f_name | char(20) | NO | | NULL | |
| pat_l_name | char(20) | NO | | NULL | |
| pat_gender | char(20) | NO | | NULL | |
| pat_age | int(20) | NO | | NULL | |
| pat_dob | date | NO | | NULL | |
| pat_blood_grp | varchar(10) | NO | | NULL | |
| pat_weight | int(10) | NO | | NULL | |
| pat_contact_no | varchar(12) | NO | | NULL | |
| pat_address | varchar(20) | NO | | NULL | |
+----------------+-------------+------+-----+---------+----------------+
$sql = "INSERT INTO patient(pat_f_name, pat_l_name, pat_gender, pat_age, pat_dob, pat_blood_grp, pat_weight, pat_contact_no, pat_address) VALUES ('$user_fname','$user_lname','$user_gender','$user_age','$user_dob','$user_bg','$user_weight','$user_contact_no','$user_address')";
I was bee-bopping along writing code and testing it when I hit this error.
update products set enable_flag='Y' where prod_id=31745
ERROR # 214 : (1054)
Unknown column 'enable_flag' in 'field list'
The "enable_flag" field is listed in the table. I have tried several variants of the above SQL command. I've put backticks around "products", around "enable_flag", I've tried retyping the command - all to no avail. I even thought that maybe I'd exceeded the length limit of 65,536 characters - but no. So I came here, read up on other's having a similar problem but those were all "You mistyped X" or "You left off the name of the table" and so forth. This has got me a bit stumped. I'm using MySQL (latest version), PHP 5.4.12, and before yesterday I have mainly worked with the first half of the table. So now I'm starting to work with the second half and this happens. Also, enable_flag is column 52. I know you can have 4096 columns. However, anything from column 52 on can not be updated, inserted, etc....
Here is the table "products" dump:
+--------------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+---------------+------+-----+---------+----------------+
| prod_id | bigint(20) | NO | PRI | NULL | auto_increment |
| sku | varchar(40) | YES | | NULL | |
| upc | varchar(40) | YES | | NULL | |
| title | text | YES | | NULL | |
| long_desc | mediumtext | YES | | NULL | |
| cat_id | int(11) | YES | | NULL | |
| size | varchar(80) | NO | | NULL | |
| color | varchar(80) | NO | | NULL | |
| model | varchar(80) | YES | | NULL | |
| quantity | int(11) | YES | | NULL | |
| stock_status_id | int(11) | YES | | NULL | |
| image_id | bigint(20) | YES | | NULL | |
| mfg_id | int(11) | YES | | NULL | |
| shipping | decimal(10,2) | YES | | NULL | |
| price | decimal(10,2) | YES | | NULL | |
| points | decimal(10,2) | YES | | NULL | |
| tax_class_id | int(11) | YES | | NULL | |
| weight | decimal(10,2) | YES | | NULL | |
| width | decimal(10,2) | YES | | NULL | |
| length | decimal(10,2) | YES | | NULL | |
| height | decimal(10,2) | YES | | NULL | |
| viewed | int(11) | YES | | NULL | |
| date_used | datetime | YES | | NULL | |
| date_added | datetime | YES | | NULL | |
| date_modified | datetime | YES | | NULL | |
| date_available | datetime | YES | | NULL | |
| sellor_id | int(11) | YES | | NULL | |
| sellor_product_id | varchar(80) | YES | | NULL | |
| state_codes | text | YES | | NULL | |
| ground_ship_only | varchar(1) | YES | | n | |
| adult_sig_req | varchar(1) | YES | | n | |
| no_drop_ship | varchar(1) | YES | | n | |
| priority | int(3) | YES | | NULL | |
| unlimited_stock | varchar(1) | YES | | NULL | |
| reorder_level | int(11) | YES | | NULL | |
| license_key | text | YES | | NULL | |
| store_cost | decimal(10,2) | YES | | NULL | |
| msrp | decimal(10,2) | YES | | NULL | |
| handling_cost | decimal(10,2) | YES | | NULL | |
| min_order_quantity | int(11) | YES | | NULL | |
| max_order_quantity | int(11) | YES | | NULL | |
| weight_major | decimal(10,2) | YES | | NULL | |
| weight_minor | decimal(10,2) | YES | | NULL | |
| warehouse | text | YES | | NULL | |
| shipping_msg | text | YES | | NULL | |
| category_special | varchar(1) | YES | | NULL | |
| homepage_special | varchar(1) | YES | | NULL | |
| shipping_option | text | YES | | NULL | |
| product_type | text | YES | | NULL | |
| related_products | mediumtext | YES | | NULL | |
| product_url | text | YES | | NULL | |
| enable_flag | varchar(1) | YES | | NULL | |
| purchasable | varchar(1) | YES | | NULL | |
| price_msg | text | YES | | NULL | |
| in_stock_msg | text | YES | | NULL | |
| out_of_stock_msg | text | YES | | NULL | |
| variations | text | YES | | NULL | |
| attributes | text | YES | | NULL | |
| delete_flag | varchar(1) | YES | | NULL | |
| short_desc | text | YES | | NULL | |
| cross_ref | text | YES | | NULL | |
| model_no | varchar(40) | YES | | NULL | |
| pkg_qty | int(11) | YES | | 1 | |
| military_spec | varchar(40) | YES | | NULL | |
| grips | varchar(80) | YES | | NULL | |
+--------------------+---------------+------+-----+---------+----------------+
In this case, the problem was the database became confused on what I actually wanted to do. There is only one "products" table so the database should not have become confused - but it did. The solution is to add the database's name on to the command so there isn't any confusion. So the command should have been:
update store.products where enable_flag='Y' where prod_id=31750
By placing the "store" part on to the command, the database.table connection is then established and the field is found.
I suspect that your enable_flag might have other characters. You can figure this out using information_schema.columns:
select concat('"', c.column_name, '"')
from information_schema.columns c
where table_name = 'products' and column_name like '%enable%';
If you find extra characters, you will probably need backticks.
I'm trying to get the number of games that summoners in the queue have played today. I have tried several queries. The closest I have gotten is:
SELECT
s.summoner,
s.wins,
COUNT(*) as playedToday
FROM summoners s
LEFT JOIN teams_players tp ON tp.summoner_id = s.summoner
LEFT JOIN teams t ON t.id = tp.team_id
LEFT JOIN matches b ON t.id = b.blue_id
WHERE
b.played_on = DATE(NOW())
s.in_queue;
But that doesn't give the count per-user. It just gets the overall count.
None of the tables have any data on any of the summoners. What I'd like is something like:
+-----------------+------+-------------+
| summoner | wins | gamesPlayed |
+-----------------+------+-------------+
| DotAliscious | 353 | 0 |
| Kraator | 440 | 0 |
| Nammon | 667 | 0 |
| VictorousSecret | 843 | 0 |
| Canas | 544 | 0 |
| Sprognak | 502 | 0 |
| Ghostilocks | 808 | 0 |
| b0b d0e | 224 | 0 |
| Metroshica | 339 | 0 |
| RubenatorX | 478 | 0 |
+-----------------+------+-------------+
I can't think how to express this problem generically, which is why I haven't found a solution.
My data set. Note that teams.id matches up with matches.blue_id and matches.purple_id.
mysql> DESCRIBE summoners;
+--------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| icon | int(11) | NO | | 0 | |
| summoner | varchar(32) | NO | UNI | NULL | |
| skype | varchar(32) | NO | | NULL | |
| email | varchar(32) | NO | | NULL | |
| in_queue | tinyint(1) | NO | | 0 | |
| wins | int(11) | NO | | 0 | |
| level | int(11) | NO | | 1 | |
| lan_wins | int(11) | NO | | 0 | |
| played_today | int(11) | NO | | 0 | |
+--------------+-------------+------+-----+---------+----------------+
10 rows in set (0.00 sec)
mysql> DESCRIBE matches;
+-----------+-------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| blue_id | int(11) | NO | MUL | NULL | |
| purple_id | int(11) | NO | MUL | NULL | |
| status | varchar(32) | NO | | display | |
| played_on | datetime | NO | | 2012-04-06 13:53:55 | |
+-----------+-------------+------+-----+---------------------+----------------+
5 rows in set (0.00 sec)
mysql> DESCRIBE teams;
+---------+-------------+------+-----+------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| outcome | varchar(32) | NO | | incomplete | |
+---------+-------------+------+-----+------------+----------------+
2 rows in set (0.00 sec)
mysql> DESCRIBE teams_players;
+-------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| team_id | int(11) | NO | MUL | NULL | |
| summoner_id | int(11) | NO | MUL | NULL | |
+-------------+---------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
You're going to want to use a subselect to get the count of records that meet the condition, and that will return you a 0 if the condition is false. Something along the lines of
(SELECT COUNT(*) FROM matches b WHERE b.blue_id = t.id AND b.played_on = DATE(NOW())) AS playedToday
and you will want to remove the LEFT JOIN to the matches table and the WHERE clause checking the date.
Your played_on is datetime and you are comparing it with date maybe that's your problem. YOu should try:
WHERE
DATE(b.played_on) = DATE(NOW())
Also what do you mean by s.in_queue? Did you forget the AND? Do you mean
WHERE
DATE(b.played_on) = DATE(NOW())
AND
s.in_queue;