I have the following situation:
table 1 -> publications
table 2 -> users
In table one among some details of publications, I have 20 fields concerning authors, exactly their names and lastnames (these fields: n1, l1, n2, l2, n3, l3...
and so on).
In table two I have one field that contains the name and the lastname of user.
I would like to display only these publications where the name and the lastname from table 1 will be the same as the name and the lastname from table 2.
Here's my query so far:
$sql ="SELECT *, concat_ws(' ',n1,l1), concat_ws(' ',n2,l2) AS my
FROM #__publications WHERE my IN
(SELECT name FROM #__users WHERE name = '".$l_user."')";
I know that probably my way of thinking is wrong. Could you help me? I will be grateful if you would give me some advice.
You should remove the authors from the Publications table and make a 3rd table that links Users with Publications.
Then your queries can just check that table to see if a user is associated with the publication. Plus, you can have as many authors as needed without adding new columns to Publications and if someone changes their name it won't break the relationship with Publications.
Here is an example (I used SQL Server for this so there might be small syntax differences):
Then when you realize I misspelled the author's last name, you can just update that one row without touching the Publications table.