0

I have a query which currently should only display one row. However it somehow is displaying 4 rows as its result set even though 1) there are only three rows in the table to begin with 2) only one row matches the query criteria.

I am hoping someone might know what I am doing wrong with this MySql query

My database table structure is as below

smsid (int, auto increment), sms_type (text), sms_status (enum 'pending',sent'), 
sms_error (test), sms_message(text), sms_mp3file (varchar 50),
sms_sendon (datetime), send_sms_toid (int 5)

My table entries are as so (following the order of the table columns above)

31 | mp3 | pending |  | | helloworld.mp3 | 2013-11-20 16:16:00 | 7

30 | text  | sent |  | hello test |  | 2013-11-18 13:12:00 | 8 

29 | voice  | sent |  | testing 123 |  | 2013-11-18 10:05:00 | 18

My query is as below

SELECT sms_messages.*, sms_recipients.cust_profid, sms_recipients.sms_cellnumber, 
customer_smsnumbers.sms_number, customer_smsnumbers.sms_number 
FROM sms_messages, sms_recipients, customer_smsnumbers
WHERE sms_messages.sms_type='mp3' AND  sms_messages.sms_sendon <= '2013-11-21' 
AND sms_messages.sms_status='pending' AND 
sms_messages.send_sms_toid = sms_recipients.smsuser_id
0

1 Answer 1

2

In your query, you have missed a JOINING clause for customer_smsnumbers table. Similar to sms_messages.send_sms_toid = sms_recipients.smsuser_id you need to have a join clause which either connects sms_messages with customer_smsnumbers table or connects sms_recipients with the customer_smsnumbers table.

In the absence of a join clause other (unintended) records are included in the result.

Sign up to request clarification or add additional context in comments.

1 Comment

+1, but what I really love when they blame MySQL for not displaying the rows

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.