SQL query to display data
Solved
okbabb
Posted messages
59
Status
Membre
-
okbabb Posted messages 59 Status Membre -
okbabb Posted messages 59 Status Membre -
7 réponses
yg_be
Posted messages
23437
Registration date
Status
Contributeur
Last intervention
Ambassadeur
1 587
okbabb
Posted messages
59
Status
Membre
It's not an exercise, it's a problem that I want solved.
First, you need to tell us which DBMS you are using...
MySQL? Access? Oracle? SqlServer? PostgreSQL? Other ??
Then, I told you to look into LEFT JOINs and ALIASES... have you done that?
MySQL? Access? Oracle? SqlServer? PostgreSQL? Other ??
Then, I told you to look into LEFT JOINs and ALIASES... have you done that?
Complicated ??
Yet, it seems pretty simple to understand to me.. https://sql.sh/cours/jointures/left-join
And a course on joins.. and aliases: https://joaomarcuraa.medium.com/sql-joins-and-aliases-1965fd2423ca
Yet, it seems pretty simple to understand to me.. https://sql.sh/cours/jointures/left-join
And a course on joins.. and aliases: https://joaomarcuraa.medium.com/sql-joins-and-aliases-1965fd2423ca
You won't find an example that perfectly matches your needs... it's up to you to understand how it works and apply it...
Start with an initial join between your two tables, see what it gives you...
then, add a second join between your two tables... and there you go... job done...
In short
Start with an initial join between your two tables, see what it gives you...
then, add a second join between your two tables... and there you go... job done...
In short
SELECT * FROM table1 T1 LEFT JOIN table2 T2 ON T2.xx = T1.zz LEFT JOIN table2 T3 on T3.ww = T1.yy
1 - Do not post images... but the code directly on the forum using the code tags!
2 - An SQL query should be tested FIRST directly in the database (using phpMyAdmin for example)
3 - You will need to add ALIASES as well in the "SELECT" part of your query to identify the fields (since you have the same ones multiple times..)
NB: Explanations regarding the use of code tags to read completely before returning:
https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
.
2 - An SQL query should be tested FIRST directly in the database (using phpMyAdmin for example)
3 - You will need to add ALIASES as well in the "SELECT" part of your query to identify the fields (since you have the same ones multiple times..)
NB: Explanations regarding the use of code tags to read completely before returning:
https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
.
No, I removed the order by and the problem still exists
The error is:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\Serveur\xampp\htdocs\projet\tableau.php on line 103
And I don't know how to use aliases so that the output displays the names of the structures (lieu_travail and affectation) of the targeted columns.
The error is:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\Serveur\xampp\htdocs\projet\tableau.php on line 103
And I don't know how to use aliases so that the output displays the names of the structures (lieu_travail and affectation) of the targeted columns.
Oh, but you're talking about a PHP error message... who cares about that!
First of all, because your question concerns the construction of an SQL query, which is posted in the Database forum... and moreover, I told you to test your queries DIRECTLY in your database before wanting to use them in code.
Not to mention that your PHP code is outdated... but I'll talk to you about that later when you've finally made the query for which you asked us for help...
First of all, because your question concerns the construction of an SQL query, which is posted in the Database forum... and moreover, I told you to test your queries DIRECTLY in your database before wanting to use them in code.
Not to mention that your PHP code is outdated... but I'll talk to you about that later when you've finally made the query for which you asked us for help...
The thing is very simple, but I don't know how to do it. Here is another example,
a table "users" that contains 4 columns: id, name, country_of_origin, country_of_residence
id name country_of_origin country_of_residence
1 michel 1 2
2 celine 3 4
and another table "countries" that contains 2 columns: country_id, country_name
country_id country_name
1 france
2 belgium
3 spain
4 switzerland
I want a final table like this: (output)
name country_of_origin country_of_residence
michel france belgium
celine spain switzerland
what is the SQL query? Thank you in advance.
a table "users" that contains 4 columns: id, name, country_of_origin, country_of_residence
id name country_of_origin country_of_residence
1 michel 1 2
2 celine 3 4
and another table "countries" that contains 2 columns: country_id, country_name
country_id country_name
1 france
2 belgium
3 spain
4 switzerland
I want a final table like this: (output)
name country_of_origin country_of_residence
michel france belgium
celine spain switzerland
what is the SQL query? Thank you in advance.


