0

My tables..

users
---------------------
pass | name | genre
---------------------
 1   | Mike | pop
 2   | Clark| rock


favorites
---------------------
id | pass | songs
---------------------
 1 | 1    | blabla
 2 | 1    | blaablaa
 3 | 1    | blblbl
 4 | 2    | lalala


suggestions
---------------------
id | pass | songs
---------------------
 1 | 1    | brrbrrr
 2 | 2    | lulala

My querys..

1. For Username and Genre

SELECT `name`, `genre` FROM `users` WHERE `name` = "Mike"
user_data = mysqli_fetch_object(query);
user_data->name;user_data->genre;

2. Count the favorite songs from ‘Mike’

SELECT COUNT(`songs`) AS "total_favorites" FROM `favorites` INNER JOIN `users` USING (pass) WHERE `name` = "Mike"
fav_dat = mysqli_fetch_object(query);
fav_dat->total_favorites; </pre></div><!-- /wp:codemirror-blocks/code-block --> <!-- wp:paragraph --><em><strong>3. Count the suggestion songs from 'Mike'</strong></em><!-- /wp:paragraph --> <!-- wp:codemirror-blocks/code-block {"showPanel":false,"languageLabel":"no","mode":"clike","mime":"text\/x-c++src"} --> 			<div class="wp-block-codemirror-blocks-code-block code-block"><pre>SELECT COUNT(`songs`) AS "total_suggestions" FROM `suggestions` INNER JOIN `users` USING (pass) WHERE `name` = "Mike"sug_dat = mysqli_fetch_object(query);sug_dat->total_suggestions;

How can I combine these 3 queries in one? Is there a better way to write them?

Anonymous Asked question May 14, 2021