I have a 2 tables that I want to select in a weird way but I'm not sure how to join them, should I use inner join or join left or group by etc...

//my desired out come


employee_id | training_name
----------------------------
   1        | training a 
            | training b 
            | training c
   2        | training d 
            | training e 
            | training f  

//my tables

employee table
   id - primary key
   name, age etc

employee_meta table
   id
   employee_id - foreign key from employee table
   training name

I'm mainly selecting from the employee_meta table since there are multiple employee_ids. I just want to group them and not have it display over and over gain like this

employee_id | training_name
----------------------------
1 | training a
1 | training b
1 | training c
2 | training d
2 | training e
2 | training f

sorry of the double post but I couldn't edit my old post

question: if I add indexes via the ALTER method, does that effect my queries? not performance wise but error wise, if my old queries will still work?

Answer second post first: You can add an index without affecting (except efficiency) your queries. However if the table is very big, adding an index can take significant tie and space (I've seen it take some hours for a table with millions of rows, partitioned by time_stamp into many sub-tables... though it was a Postgres database, come to think of it, I would expect any database to act about the same, since an index is basically another table, and the database will have to walk the indexed table sequentially creating the index values for each row)

Answer first question second: I don't think you can easily do that (you can "un"easily do many things with SQL, so it might be possible) Bear in mind that the basic nature of a SELECT statement is to return fully populated tuples, so eliding some of the contents of one of the columns is going against SQL's basic nature. If you really need that layout, where you can spell "need" as "want" if you (need) to:), then you probably should do it in the view code, not the select code ... and that is assuming you have some kind of MVC program where the database is the Model, and there is some Viewer.

@griswolf

@Answer second post :

thanks for the info, good thing my database is pretty small, about 20k worth of rows I need indexing. I hope that InnoDB won't be a problem when I add the index

@Answer first question :

right now I'm doing most of it in php and I was able to achieve the end result, though it took awhile to load though.

Thanks again for the info, hopefully my indexing is successful and without errors.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.