How to search multiple tables for a keyword regardless of which table or column it would be in?
I am looking for information relating to for example a name or phrase which maybe in one or multiple tables in any column.
Related
I have two different databases and in one database, I have "tblcontacts" table and when we create same name table in another database, it shows me error.
#1050 - Table 'tblcontacts' already exists.
I want same name table in two different databases.
please help me to get this.
I want to design a database with two table, related to each other.
But I can't relate one row to more than one row in another table.
PLUS: I just want use MySQL ability . don't like to seprate them with "," or other signs and let my PHP app check all rows
this pic might help you to understand the problem :
You have m-n relation, which means that one artist can have more than one song, but also one song can have more artists (the problem you point out). So the link between songs and artists cannot be in the songs table as you suggest, neither in the artists table - you can have only one record per row.
You need another table that relates songs and artists:
song_id artist_id
1 2
2 2
...
6 2
6 4
...
Create a new table called artist_song with only two fields artist_id, song_id.
Then remove field related_artist.
Now you can store more than one related records in this new table.
First of all you need to store array/set in a table which will work as foreign key. Mysql supports Set as datatype(mysql set datatype which is limited and kinda fixed) where postgre and oracle have array/varray(more flexible) as datatype.
Secondly, I once used orm(hibernate) to solve this problem using a wrapper class for that specific table. I am pretty sure that referencing from a array type will hurt the atomicity of DB.You can see this for referencearray as foreign key in oracle
So its not possible in mysql of what you want(unless ...).Solution of Tomas is the best one still.
I have to join multiple tables, some with one to many mappings, and convert every entry in the joined table to a single row entry in a csv file using PHP.
I know I am basically going from a 3D to 2D representation, but it is a formatting requirement for the csv file.
The MySQL structure consists of tables "questions", "people" and "trips". "people" table is linked to "questions" table by the id of "questions". Also in the same way "trips" is linked to "people" by the id of "people". There are one to many relationship between both "questions" to "people" and "people" to "trips"
The idea is to have a csv file with one "question" entry per row. This row entry will be the joined result of all 3 tables. The number of people and trips per questions entry is not consistent, therefore spaces are required if there are fewer people in some "questions" entries than other. The same with the trips.
What is the best way to get this done in PHP, except for brute force coding this with many queries, for loops etc. I am trying to get the MySQL query going, but cannot wrap my head around this problem.
I think you're looking for mysql GROUP_CONCAT function.
Select data with joins, group it by question_id and use group_concat on people and trips columns.
I've got this database with about 26 tables (field names are the same in each table) and i was wondering how simple it would be to do a general search on my website based on a keyword which will search through all tables?
Eg Each table has title, author etc etc so if i had a keyword of hairspray - whats the best way to look for the keyword through all tables..
Preferably not through a join or union due to the amount of tables
Cheers in advance
Its a very bad way, of creating tables.
If they share a common schema they should be one single table, with some additional field to separate or distinguish the data.
If this is not going to be an option for you, you might want to create a temporary table, which will hold all the data from all 26 tables, then query this table for the search.
I wondered how a table should be structured when there is going to be more than one value for a certain field. For example, If I have a user who has 10 friends should there be a table that has 10 rows with the user's name and a different friend on each row or should there be one row with the user's name and all the friends put into one? Thanks, the answers will help a lot.
You should make a many-to-many table that links the foreign keys together of two people who are friends. So if Person is the entity you are using, you wouldn't want to constrain the structure by introducing limitations such as 10 friends into a single row.
Fundamentally, what you're trying to do is normalize your data. You should read up a bit on Database Normalization