Combine various tables when multiple IDs are stored in a single row

Within my database, I have three tables: skill, job_post, and experience. My task involves joining these tables together.

Firstly, the job_post table is structured as shown here:

https://i.stack.imgur.com/lySaZ.png

The layout of the Skill table is as follows:

https://i.stack.imgur.com/r2h3S.png

Lastly, the Experience table appears like this:

https://i.stack.imgur.com/PAKED.png

My goal now is to join all of the above tables. Initially, I am joining the job_post and experience tables using the following query:

"select * from job_post as jp 
  join experience as e on e.exp_id = jp.exp_id
  where jp.emp_id in (".$ids.")"

However, since multiple skill_ids are included in the job_post table, I am faced with the challenge of joining the job_post table to the skill table.

Note: To tackle this issue, I initially wrote the above join query, followed by creating a foreach loop to extract the skill ids from the job_post table. Subsequently, I wrote a query to match these skill ids with the skill table and display the skills.

Despite this approach, I am curious if there is a more concise way to achieve this through a single query instead of the workaround mentioned above?

Answer №1

To accomplish the third join, you can utilize MySQL's find_in_set and group_concat:

select jp.*,e.*,group_concat(s.skill)
from job_post jp 
join experience e on e.exp_id = jp.exp_id
join skill s ON(FIND_IN_SET(s.skill_id, jp.skill) > 0)
where jp.emp_id in (".$ids.")
GROUP BY jp.job_id,jp.exp_id

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Refresh the click event on a newly added element in the backbone framework

As a newcomer to backbone.js and using CodeIgniter as my PHP Framework, I encountered a challenge while developing an existing system that uses a backbone.js library. The problem is straightforward if approached with jQuery, but due to the use of backbone ...

Troubleshooting issues with Laravel and Carbon while trying to extract the month from a datetime

Seeking some assistance. I must confess, this might be a simple question for most, but as someone who isn't proficient in programming, I ventured into creating an app with Laravel without having a solid grasp on the fundamentals of PHP. Currently, I ...

What is the standard size for PHP files, or the suggested maximum limit?

I created a tool at where users can upload a .php file with comments and spaces, and it will compress it for a smaller file size. It functions similar to but is web-based and provides instant results. Once you click upload, you receive a prompt to downl ...

Send the id of the chosen row to the Component tag within the blade file

I'm working on passing the id of the currently selected row within a for loop when it's clicked on. The goal is to then pass that id to a Vue component. In my index.blade file: @foreach($cats as $cat) <tr> <td class="catme" d ...

Determine the size of a SWF file using PHP

Is there a way to load an swf file and automatically calculate its dimensions using PHP? For those who are looking for a solution, here's what worked: $fileInfo = getimagesize($filePath); list($width, $height) = $fileInfo; ...

HTML with embedded PHP script

i cannot seem to display mysql data in html format. the table i am working with is called App appid | app | version | date | apk file | 1 sample 1.0.0 2012-10-12 sample.apk //here is the mysql query ...

What is the best way to use shortcodes to display custom fields for post objects, specifically products, within WordPress posts

I'm in the process of displaying 'featured products' within my blog posts. These specific products need to be chosen using custom post objects on the backend for each individual post. I've outlined what I believe the PHP code should lo ...

Managing asynchronous requests with CodeIgniter

In my approach to handling success and error messages, I have been using json encoded arrays as responses. However, it recently occurred to me that this may not be the most appropriate way to manage notifications. Here's an example of how I handle th ...

php resize images easily using PHP

After spending some time searching, I came across some perplexing and intricate material that I struggled to make sense of. I've been working with chronoforms in Joomla to create a form with an upload file script. The good news is that the script suc ...

The index array function of PHP's explode algorithm

When using PHP's explode function with the code below $data="test_1, test_2, test_3"; $temp= explode(",",$data); The resulting array looks like this array('0'=>'test_1', '1'=>'test_2', 2='test_3&ap ...

Combining two associative arrays in PHP

I am facing an issue with two separate arrays. Array 1: Array ( [0] => Array ( [id] => 1 [name] => Product 1 [quantity] => 2 [unit_amount] => Array ( ...

The initial Sequelize schema is being replaced by multiple new schemas

My current setup involves using Sequelize ORM to connect to two separate schemas. Within my models folder, I have organized the schema models into two folders - tenants and superadmin, each containing their respective model.js files. The index.js file with ...

Strip the whitespace from the elements of the string

At runtime, I have a string that I explode into separate elements (tags) inputted via a text field. The goal is to remove extra white spaces before and after the ,. Here is an example of the string: $str = "tags,more tags ,even more tags, great art, pai ...

Interfacing with a PHP script hosted on my server through Java programming

In order to securely access my database, I am looking to utilize a PHP script instead of directly accessing it with Java. This way, I can avoid having the username and password for a read-write account stored in my Java code, which could potentially lead t ...

What advantages does NuSOAP offer over PHP SOAP?

After extensively searching the internet, I've come across numerous articles discussing how to configure NuSOAP and utilize it for setting up a SOAP server and client in PHP. Interestingly, none of these sources highlight any specific advantages of u ...

What is the process for assigning a name and value to a DOMNode in PHP?

The `DOMNode` class includes the attributes `nodeName` and `nodeValue`, but lacks setters for them. It's possible to directly access the public attribute `nodeValue`, but how can one set the read-only `nodeName`? ...

Sending mail to multiple recipients using Yii mailer

Looking for help on sending mail to multiple recipients using Yii mailer. I have written code that successfully sends emails to a single recipient, but I am struggling to make it work for multiple recipients. $mail_ids = $_POST['invitefriend']; ...

What distinguishes using a period and comma for concatenation with echo versus return?

After some testing, I discovered that the following code works: echo $value , " continue"; However, this code does not work as expected: return $value , " continue"; In both the echo and return statements, using a period instead of a ...

PHP is experiencing a delay of an additional second in fetching each result set from Sphinx!

After working perfectly fine the night before, I encountered a strange issue today. The problem arose after reinstalling WAMP on my local dev server and attempting to retrieve results from Sphinx using the PHP API. For testing purposes, I executed a basic ...

Why does the appearance of my PHP spreadsheet change when I attempt to print it?

After using a CSS stylesheet to position my textboxes correctly, I noticed that in Chrome everything appeared fine. However, when attempting to print the site (Ctrl+P), each sentence and textbox shifted. How can I ensure they remain in place? <!-- #cap ...