Discuss [MySQL] Relations, connect by two fields in the MySQL Help forum on Dev Shed. [MySQL] Relations, connect by two fields MySQL Help forum discussing administration, SQL syntax, and other MySQL-related topics. MySQL is an open-source relational database management system (RDBMS).
Receive the tools necessary to be the rock star of your field. Our 12-month program teaches you the evolving world of multi-channel marketing as well as the complex issues and opportunities found in the industry.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Web development can be a daunting task, even for specialists. There is a lot of information to absorb and a lot of technologies to learn in order to manage a superior website. When trying to learn the ropes, developers need a reliable source to introduce new ideas that can be easily implemented. When working on large projects, even web veterans may run into a technology or an aspect of a technology that they are unfamiliar with.
Posts: 2
Time spent in forums: 54 m 34 sec
Reputation Power: 0
[MySQL] Relations, connect by two fields
Hello,
I request to you for help in solving my problem. I have two tables in a database that I need to connect in a fairly specific way.
Code:
TABLE 1: contains a list of all registered users
id username
1 user1
2 user2
3 user3
4 user4
5 user5
Code:
TABLE 2: lists the files that have been flagged by users as being inconsistent with the terms and conditions
id user_id uploader_id
1 1 3
2 2 3
3 3 2
4 1 3
5 1 4
How to extract of Table 1 only those users who appeared in table2 in field: user_id or uploader_id? I need to create links to users details based on their username (no id) so I need to connect in some way, these tables. I'll be very grateful for your help.
Posts: 2
Time spent in forums: 54 m 34 sec
Reputation Power: 0
Both methods work very well. Thank you.
Now another problem.
I need a list of users who are in the field user_id, uploader_id in Table 2.
The problem is that the table1 has more than 1 million records so to create a list I need to use pagaination. To do pagination I need to know how many users appears in the fields user_id, uploader_id in table 2.
I used this query:
Code:
SELECT COUNT(DISTINCT(t1.id))
FROM table1 t1 INNER JOIN table2 t2
ON t1.id IN ( t2.user_id , t2.uploader_id )
It's takes far too long. Could you prompt some other solution?