There are two tables: in one project, and in another keywords to them. This query takes data from two tables at once:

SELECT * FROM pos_projects JOIN pos_keywords ON pos_projects.id = pos_keywords.pid WHERE pos_projects.userid= :userid ORDER BY id DESC 

But from the second table it takes only one line, and how to pick up everything?

  • remove WHERE pos_projects.userid= :userid - Mirdin
  • This is a necessity. I need to select projects of a specific user only. And pos_projects is the first table, I need to pick up all the projects from it, and from the second ( pos_keywords ) pick up all the lines for each project - Mr. Andrew
  • Well, it means that this user has only one project. - Mirdin
  • Add problem data to the question. As long as your desired behavior matches the structure of the request. - 4per
  • one
    @ 4per He is what the author of the question wrote. If you think it should look different, please make a better edit! Made changes, if something is wrong, write, improve together! - Nicolas Chabanovsky

1 answer 1

As an example (alternative) - there are cities (cities) and countries (countries), the city has countryId = countries.id. To select all the cities for a particular country, I write:

 SELECT countries.name, cities.name FROM countries join cities on countries.id = cities.countryId where countries.name = 'Испания'; 

I get two columns - the first is the name of the country, the second is the city.

At you it returns all data from projects, but nothing from words (since select * from pos_projects is written, and all)