Ask the SQL Query 2 table questions

Source: Internet
Author: User
Ask the SQL Query 2 table questions:
A table is
ID Title Picid
Where Picid storage information is
A:4:{s:6: "Attach"; S:2: "S:9", "Show_type", s:1: "0"; S:9: "User_bind"; s:1: "1"; s:10: "Topic_bind"; s:0: "";}

Table B is
p_id purl
I first obtained the attach data in the Picid field by querying a table, and the output is in the form of an array of
aryy{
"0" 74
"1" 88
....
}
So how can I query the attach of table A to find the matching ID of B p_id 74 88?
Can you give me a code to explain?


Reply to discussion (solution)

Set the first step to get an array of
$ar = Array (74, 88);
Then there are
$sql = ' Select ' from table B where p_id in ('. Join (', ', $ar). ')';

If the order in which attach appears in Picid is fixed, you can also directly correlate two table queries

Like what
Select p_id, purl from table B, table A WHERE p_id = Substring_index (Substring_index (Picid, 4), ' "',-1)

Set the first step to get an array of
$ar = Array (74, 88);
Then there are
$sql = ' Select ' from table B where p_id in ('. Join (', ', $ar). ')';

If the order in which attach appears in Picid is fixed, you can also directly correlate two table queries

What if the order of occurrence is not fixed? Can I associate two table queries?

Use the LOCATE function first to locate, should also be possible

  • 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.