How to "inner join" two website DB's - mysql

I have a requirement and would like to know the best way of achieving the goal.
The idea is to "inner join" two tables from two databases from two completely different websites.
For example, I have a website that tables ID's from another source. I then want to analyse those ID's in more detail by joining my table with the other websites table.
My initial thought would be to pass a JSON list of ID's from my table to a php file on the 3rd party host, which would then do a "select fields from table where id in (JSONList)", then pass back the information of which I would then stitch together and display.
Is there a better / easier way of doing this?

You can do it directly in the database, which allows you to use sql.
MySql will allow you to create a Federated Table locally, that when accessed will pull the data automatically from the remote database.
Once you've got your federated table setup you should be able to write your join normally e.g:
select * from table1 inner join table2 on table1.joinkey = table2.joinkey;
There are a number of related questions already if this is the approach you wish to take (or at least try):
MySQL: SELECT from another server
I need to join table from other database and sometimes other server
https://dba.stackexchange.com/questions/81411/select-in-federated-table-is-to-slow
Unfortunately the docs say this will only currently work for mysql to mysql: http://dev.mysql.com/doc/refman/5.1/en/federated-create-connection.html

Related

SQL Database architecture with multiple end Users

I am making a web application where users get and manage data from multiple tables as well as create other users to access said data. currently I have it set up for one group of users.
My question is would it be better to have multiple databases in which each database has its own user which is stored in a master table("I don't like the sound of this one") or have a column in each table defining the user group that has access to it? Are either of these a good idea or is something else more appropriate?
You should have a column in each table. In my opinion, its the correct thing to do, and also you have only one database to do mantainance.
Just imagine the time it would take to add a column to a table in the future, and you should do it in multiple databases.

Connect Tables in MySQL

I'm attempting to connect two tables in MySQL so that when selected, a value is pulled from the table.
Table 1
id
mobile_car
Table 2
id
mobile_car
car_domain
When the mobile_car is selected via a dropdown and the user registers this, I would like to be able to have it connect to the car_domain so I can call this later in the application.
For example, if the user selects "Verizon" as their mobile_car, I would like it to link to the car_domain "#vtext.com" so I can connect their phone number with the car_domain. Essentially, I'm sending a text by way of emailing their cell number.
I know there are programs and pre-built options, but I'd like an understanding of how this could be done.
Thanks!
Try joining your two tables together:
SELECT t1.mobile_car, t2.car_domain
FROM Table1 t1 INNER JOIN Table2 t2
ON t1.mobile_car = t2.mobile_car
I'm also assuming that your actual table structure will be more complex than this, since right now you can actually just query Table 2 by itself to get what you need.

Keeping all columns in a single table vs keeping in separate table by category of data

I've a mysql table "login" with columns name, userid, pass, email. and another table "info" with columns bio, skills, searchingfor, badge, likes, age
here, the 1st table is used to check login... and the rest is used for storing personal info of an user. but i have a search box where people can search user according to everything except bio & pass. I'm having problem joining the results from two tables so is it ok to put all in one table or is there a simplier way?
and if i put everything in a table would it be heavier for mysql queries to search if the database gets lots of data?
There is no higher load on your mysql server if you combine both tables. This is a valid idea, since it appears that you have a 1:1 relationship anyway, so the code get's easier. Actually the load will be lower, since you do not need a join which is actually very slow in relational database management systems. The performance (load) just depends on your indexes and filter requirements, but that is independent of whether you search in one or two tables.
On the other hand: there is no reason why you should not be able to join those tables as required. So maybe you want to solve your issue here first. And be it just to learn how to do do it ;-)

SQL Inner joining a column from two tables with a single user id

I've been trying to get this SQL query running for a while now and can't seem to get the last little bit going.
The backend database to all this data is a Drupal install with data spread out across a number of modules, so I need to do a lot of joining to get a certain view table set up that I need for a third-party application.
It's hard to explain the entire schema, but here's the sqlfiddle:
http://sqlfiddle.com/#!2/68df0/2/0
So basically, I have a userid which I map to a profile id through a join. Then I need to use that profile ID to pull the related data about that profile from two other tables. (there should only be one row with each pid in each of the other tables)
So in the end, I would like to see a table with username, othername, and key_id.
I got the first two pieces in there, but just can't seem to figure out how to join in the othername, and keep getting null.
The server is running MySQL.
Thanks guys!
LEFT JOIN other_name
ON profile_link.pid=other_name.pid;

Enabling view of relational database values in microsoft access (2007)

I am creating a relational database for a friend and I have never used MS Access before. I am trying to make it so that the related values are shown on a table view rather than the numeric representation. For example, instead of
[1][2242], [2][443]
I would like
[1][John Smith], [2][Marilyn Monroe]
(the first value being the primary key and the second being the value linked to another table).
I have read this page about creating relationships between tables but I am still having trouble "viewing" the linked values. Microsoft Access is going to be the only way my friend is going to be viewing these results so that is why it is important to be able to see the correct values.
I have made relational databases before but only with traditional PHP and SQL and so I know what I need to do but I cannot seem to do it.
Any help would be appreciated.
Do not be misled into creating lookup values in tables. Create a form and add comboboxes to display the data from the related table, or use queries.
For example: create form to add records in multiple tables
Or
SELECT Id, Fullname FROM Table1
INNER JOIN Table2
ON Table1.FKID = Table2.ID
You can create the relationships visually in MS Access. You can also build queries in the query design window.