Ask questions about the statements of two MYSQL tables

Source: Internet
Author: User
Ask questions about the statements of two MYSQL tables
$sql = "SELECT a.id,a.cover,a.name,a.name2,b.id,b.likes,b.month FROM dede_aiyunma_user AS a,dede_aiyunma_thing AS b WHERE a.id=b.id order by a.id desc";$dsql->Execute('me',$sql);while($row = $dsql->GetArray('me')){$uid = $row['id'];$cover = $row['cover'];$fname = $row['name'];$mname = $row['name2'];$like = $row['likes'];}

You can view the data in Table a and Table B. Now, the B. likes field is required to be displayed according to the B. month field. how can this statement be changed?
If it becomes WHERE. id = B. id and B. month = $ month order by. id desc, which is the condition of two tables, so that where B. month = $ month only applies to Table B. How do I write?


Reply to discussion (solution)

B. month = $ month is used only for Table B.

B. month = $ month is used only for Table B.


Hello, I feel like a reply
$sql = "SELECT a.id,a.cover,a.name,a.name2,b.id,b.likes,b.month FROM dede_aiyunma_user AS a,dede_aiyunma_thing AS b WHERE a.id=b.id and b.month= $month order by a.id desc";$dsql->Execute('me',$sql);while($row = $dsql->GetArray('me')){$uid = $row['id'];$cover = $row['cover'];$fname = $row['name'];$mname = $row['name2'];$like = $row['likes'];}

After the B. month = $ month condition is added, the data in table A ($ uid $ cover $ fname $ mname) is not displayed. the requirement is that $ like is changed according to $ month.

Your connection condition is a. id = B. id
Your filtering condition is B. month = $ month
If no result is returned, no matching record exists in B.

So, is your B. month numeric?

Thank you for your patience.

Your connection condition is a. id = B. id
Your filtering condition is B. month = $ month
If no result is returned, no matching record exists in B.

So, is your B. month numeric?


Well, B. month is a numeric int.
Still don't understand. B does not have a qualified record, but the variables in a cannot output data.
Now, my goal is to query and output the data of Table a. Table B only returns 0 if the likes field with month as the condition is not found.
I don't know whether it's my code or SQL, so it's hard for beginners.

In this case, you can write it in the back and sort it by a. id.

If you want to follow B. month = $ month, you can only write another sentence.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.