What should I do if the query results of two tables are repeated?

Source: Internet
Author: User
What should I do if the query results of two tables are repeated? Table
Id title
1 123
2 456
3 789
....
Table B
Id name
1 987
2 654
3 321
....
The SQL code is
Select Table A. *, Table B. * from Table A, Table B where A. id in (1, 2, 3)
How can I avoid displaying the number of duplicates in the query results ??


Reply to discussion (solution)

It is inevitable that you have not joined two tables.

So?
Select Table A. *, Table B. * from Table A, Table B where A. id = B. id A. id in (1, 2, 3)

Correction
Select Table A. *, Table B. * from Table A, Table B where A. id = B. id and A. id in (1, 2, 3)

Correction
Select Table A. *, Table B. * from Table A, Table B where A. id = B. id and A. id in (1, 2, 3)
However, the IDs of the two tables are different.

However, the IDs of the two tables are different.
Since there is no connection between the two tables, what do you make them together? Joe taishou?

This post was last edited by xuzuning at 18:57:31
Reference the reply of u010184133 on the 4th floor: But the IDs of the two tables are different.
Since there is no connection between the two tables, what do you make them together? Joe taishou?
Fields are not associated and information is associated. can only foreach be used?

We recommend that you paste the table results, test data, and expected results, and briefly describe the business logic.

The overall situation is as follows:
Table A structure
Id name info
1 topic 1 (storage style is a: {s: 6: "picid"; s: 2: "74"; s: 9: "text"; s: 1: "Storage content area ";})
2 Topic 2 (storage style is a: {s: 6: "picid"; s: 2: "75"; s: 9: "text"; s: 1: "Storage content area ";})
B table structure
Id url
74 image path
First, an array with the ID of picid in info of Table A is obtained through the query.
Output style:
Array
(
[0] => 74
[1] => 75
)
Then, query the data whose id is in Table B.
Then, how can we associate and output the content of the two tables?
How is the output result:
Array
(
[0] => Array
(
[Id] => 1
[Name] => Topic 1
[Url] => image path
[Info] => text content in info
)

[1] => Array
(
[Id] => 2
[Name] => Topic 1
[Url] => image path
[Info] => text content in info
)
....

Retrieve the expression of text in info
Substring_index (substr (info, locate ('"text"', info), '"', 4), '"',-1) as info

Join conditions for two tables
Table B. id = substring_index (substr (info, locate ('"picid"', info), '"', 4), '"',-1)

Now there are duplicates. In fact, you can use Group by to Group the duplicates indirectly.

Retrieve the expression of text in info
Substring_index (substr (info, locate ('"text"', info), '"', 4), '"',-1) as info

Join conditions for two tables
Table B. id = substring_index (substr (info, l ......
I would like to ask what 4 means?

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.