php - MySQL query with Foreign Key -


i have following tables related shown below.

~~~~articles~~~~~~      ~~~~categories~~~~         ~~~user_categ~~~    ~~users~~~ |  id_articles    |      |  c_id          |       |   user_cat_id  |  _|_user_id | |  article_title  |     _|_ category_id   |_____  |   user_id_fk   |_/ |user_name| |  article_content| _ -  |  category_name |     \_|__category_id_fk|   |user_pw  | |  category_id    |/     |________________|       |________________|   |_________|  |_________________| 

now in user_categories table let's have following data.

| user_id_fk | cat_id_fk | ------------------------- | 2          | 2.1       | | 2          | 3.1       | | 2          | 4.1       | | 3          | 2.4       | ------------------------- 

now, want make query in mysql user_id_fk 2 article_title,article_content articles table respective categories, such 2.1 , 3.1 , 4.1.

i tried making queries inner joins wasn't successful results wanted.

hope clear enough.

you can make subqueries. example:

select article_title, article_content  articles  category_id in (   select category_id_fk user_categories user_id_fk = 1 ) 

same example join:

select article_title, article_content  articles  join user_categories on category_id = category_id_fk user_id_fk = 1 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -