How to calculate opening and closing stocks for particular date range
I want to calculate opening and closing stocks for items for a provided date range.
I have tables as follows,
global_items:
+-----+--------+
| id | name |
+-----+--------+
| 1 | item 1 |
+-----+--------+
| 2 | item 2 |
+-----+--------+
| 3 | item 3 |
+-----+--------+
| 4 | item 4 |
+-----+--------+
| ... | ... |
+-----+--------+
my_items:
+-----+----------------+-----------+
| id | global_item_id | outlet_id |
+-----+----------------+-----------+
| 1 | 1 | 7 |
+-----+----------------+-----------+
| 2 | 2 | 7 |
+-----+----------------+-----------+
| 3 | 3 | 7 |
+-----+----------------+-----------+
| 4 | 4 | 7 |
+-----+----------------+-----------+
| ... | ... | ... |
+-----+----------------+-----------+
my_item_stocks:
+-----+------------+---------+---------------+-----------+---------------+-------+
| id | my_item_id | size_id | purchase_rate | sale_rate | opening_stock | stock |
+-----+------------+---------+---------------+-----------+---------------+-------+
| 1 | 1 | 10 | 100 | 200 | 0 | 0 |
+-----+------------+---------+---------------+-----------+---------------+-------+
| 2 | 1 | 11 | 100 | 200 | 0 | 5 |
+-----+------------+---------+---------------+-----------+---------------+-------+
| 3 | 2 | 10 | 100 | 200 | 1.05 | 1.05 |
+-----+------------+---------+---------------+-----------+---------------+-------+
| 4 | 3 | 12 | 100 | 200 | 10 | 10 |
+-----+------------+---------+---------------+-----------+---------------+-------+
| ... | ... | ... | 100 | 200 | 0 | 1 |
+-----+------------+---------+---------------+-----------+---------------+-------+
sizes:
+-----+--------+----------+
| id | name | quantity |
+-----+--------+----------+
| 10 | 750 ml | 750 |
+-----+--------+----------+
| 11 | 500 ml | 500 |
+-----+--------+----------+
| 12 | 350 ml | 350 |
+-----+--------+----------+
| ... | ... | ... |
+-----+--------+----------+
Then I have sales and purchases tables as follows, adding purchase updates the stock in my_item_stocks and adding sale reduces stock.
purchases:
+-----+------------+-----------+
| id | date | outlet_id |
+-----+------------+-----------+
| 1 | 2018-07-01 | 7 |
+-----+------------+-----------+
| 2 | 2018-07-10 | 7 |
+-----+------------+-----------+
| 3 | 2018-07-19 | 7 |
+-----+------------+-----------+
| ... | ... | ... |
+-----+------------+-----------+
purchase_items:
+-----+-------------+------------+---------+----------+
| id | purchase_id | my_item_id | size_id | quantity |
+-----+-------------+------------+---------+----------+
| 1 | 1 | 1 | 10 | 2 |
+-----+-------------+------------+---------+----------+
| 2 | 1 | 2 | 11 | 5 |
+-----+-------------+------------+---------+----------+
| 3 | 2 | 2 | 10 | 17 |
+-----+-------------+------------+---------+----------+
| 4 | 3 | 2 | 12 | 15 |
+-----+-------------+------------+---------+----------+
| 5 | 3 | 2 | 12 | 10 |
+-----+-------------+------------+---------+----------+
| ... | ... | ... | ... | ... |
+-----+-------------+------------+---------+----------+
sales:
+-----+------------+-----------+
| id | date | outlet_id |
+-----+------------+-----------+
| 1 | 2018-07-01 | 7 |
+-----+------------+-----------+
| 2 | 2018-07-10 | 7 |
+-----+------------+-----------+
| 3 | 2018-07-19 | 7 |
+-----+------------+-----------+
| ... | ... | ... |
+-----+------------+-----------+
sale_items:
+-----+-------------+------------+---------+------+
| id | sale_id | my_item_id | size_id | quantity |
+-----+---------+------------+---------+----------+
| 1 | 1 | 1 | 10 | 1 |
+-----+---------+------------+---------+----------+
| 2 | 1 | 2 | 11 | 2 |
+-----+---------+------------+---------+----------+
| 3 | 2 | 2 | 10 | 10 |
+-----+---------+------------+---------+----------+
| 4 | 3 | 2 | 12 | 5 |
+-----+---------+------------+---------+----------+
| 5 | 3 | 2 | 12 | 2 |
+-----+---------+------------+---------+----------+
| ... | ... | ... | ... | ... |
+-----+---------+------------+---------+----------+
Now for selected date range e.g. from 2018-07-01 to 2018-07-19 I want the output like below,
+-----------+--------------------------+--------------------------+--------------------------+--------------------------+
| Item Name | Opening Stock | Purchase | Sale | Closing Stock |
+ +--------------------------+--------------------------+--------------------------+--------------------------+
| | 750 ml | 500 ml | 350 ml | 750 ml | 500 ml | 350 ml | 750 ml | 500 ml | 350 ml | 750 ml | 500 ml | 350 ml |
+-----------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
| Item 1 | | | | 2 | 5 | | 1 | 2 | | 3 | 7 | |
+-----------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
| Item 2 | 1.05 | | | 17 | | | 10 | | | 8.05 | | |
+-----------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
+-----------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
I am not sql pro, how can I achieve this? I am confused because of lot of related tables, just want right direction.
I am doing this is laravel so please suggest even if there is any way to achieve this using eloquent.
Models: GlobalItem, MyItem, MyItemStock, Size, Purchase, PurchaseItem, Sale, SaleItem
Many thanks!
Related
I'm trying to come up with a stored procedure that takes multiple rows that are exactly identical, and combines them into one row while summing one column, which can then be run through more stored procedures based on the sum of that one column.
I've tried a GROUP BY statement, but that doesn't actually group the rows together, because if I run the table through another procedure it performs actions as if each row were not combined. Performing a SELECT * FROM mytable query shows that each row was not actually combined into one.
Is there any way to permanently combine multiple rows into one singular row?
To start, I've got a table like this:
+-------+-----+--------+---------+------+-----+-----------+
| RowID | pID | Name | Date | Code | QTY | Purchased |
+-------+-----+--------+---------+------+-----+-----------+
| 1 | 1 | bob | 9/29/20 | 123 | 1 | |
| 2 | 1 | bob | 8/10/20 | 456 | 1 | |
| 3 | 2 | rob | 9/15/20 | 123 | 1 | |
| 4 | 2 | rob | 9/15/20 | 123 | 1 | |
| 5 | 2 | rob | 9/15/20 | 123 | 1 | |
| 6 | 2 | rob | 9/15/20 | 123 | 1 | |
| 7 | 2 | rob | 9/15/20 | 123 | 1 | |
| 8 | 3 | john | 7/12/20 | 987 | 1 | |
| 9 | 3 | john | 7/12/20 | 987 | 1 | |
| 10 | 4 | george | 9/12/20 | 684 | 1 | |
| 11 | 5 | paul | 2/2/20 | 454 | 1 | |
| 12 | 6 | amy | 1/12/20 | 252 | 1 | |
| 13 | 7 | susan | 5/30/20 | 131 | 1 | |
| 14 | 7 | susan | 6/6/20 | 252 | 1 | |
| 15 | 7 | susan | 5/30/20 | 131 | 1 | |
+-------+-----+--------+---------+------+-----+-----------+
By the end, i'd like to have a table like this:
+-------+-----+--------+---------+------+-----+-----------+
| RowID | pID | Name | Date | Code | QTY | Purchased |
+-------+-----+--------+---------+------+-----+-----------+
| 1 | 1 | bob | 9/29/20 | 123 | 1 | |
| 2 | 1 | bob | 8/10/20 | 456 | 1 | |
| 3 | 2 | rob | 9/15/20 | 123 | 5 | |
| 4 | 3 | john | 7/12/20 | 987 | 2 | |
| 5 | 4 | george | 9/12/20 | 684 | 1 | |
| 6 | 5 | paul | 2/2/20 | 454 | 1 | |
| 7 | 6 | amy | 1/12/20 | 252 | 1 | |
| 8 | 7 | susan | 5/30/20 | 131 | 2 | |
| 9 | 7 | susan | 6/6/20 | 252 | 1 | |
+-------+-----+--------+---------+------+-----+-----------+
Where exactly identical rows are combined into one row, and the QTY field is summed, that I can then add purchases to, or make deductions from the quantity as a total. Using GROUP BY statements can achieve this, but when I go to alter the quantity or add purchases to each person, it treats it like the first table, as if nothing was actually grouped.
So you have this table:
| RowID | pID | Name | Date | Code | QTY | Purchased |
+-------+-----+--------+---------+------+-----+-----------+
| 1 | 1 | bob | 9/29/20 | 123 | 1 | |
| 2 | 1 | bob | 8/10/20 | 456 | 1 | |
| 3 | 2 | rob | 9/15/20 | 123 | 1 | |
| 4 | 2 | rob | 9/15/20 | 123 | 1 | |
| 5 | 2 | rob | 9/15/20 | 123 | 1 | |
| 6 | 2 | rob | 9/15/20 | 123 | 1 | |
| 7 | 2 | rob | 9/15/20 | 123 | 1 | |
| 8 | 3 | john | 7/12/20 | 987 | 1 | |
| 9 | 3 | john | 7/12/20 | 987 | 1 | |
| 10 | 4 | george | 9/12/20 | 684 | 1 | |
| 11 | 5 | paul | 2/2/20 | 454 | 1 | |
| 12 | 6 | amy | 1/12/20 | 252 | 1 | |
| 13 | 7 | susan | 5/30/20 | 131 | 1 | |
| 14 | 7 | susan | 6/6/20 | 252 | 1 | |
| 15 | 7 | susan | 5/30/20 | 131 | 1 | |
The best way, as has been suggested, is to create a new table with the content of your query, then to rename the old table, and the new table to the original table's name, to check if everything is all right, and to drop the original table if yes.
CREATE TABLE indata_new AS
WITH grp AS (
SELECT
MIN(rowid) AS orowid
, pid
, name
, MAX(date) AS date
, code
, SUM(qty) AS qty
FROM indata
GROUP BY
pid
, name
, code
)
SELECT
ROW_NUMBER() OVER(ORDER BY orowid ASC) AS rowid
, *
FROM grp;
ALTER TABLE indata RENAME TO indata_old;
ALTER TABLE indata_new RENAME TO indata;
-- if "indata" now contains the data you want ...
SELECT * FROM indata;
-- out rowid | orowid | pid | name | date | code | qty
-- out -------+--------+-----+--------+------------+------+-----
-- out 1 | 1 | 1 | bob | 2020-09-29 | 123 | 1
-- out 2 | 2 | 1 | bob | 2020-08-10 | 456 | 1
-- out 3 | 3 | 2 | rob | 2020-09-15 | 123 | 5
-- out 4 | 8 | 3 | john | 2020-07-12 | 987 | 2
-- out 5 | 10 | 4 | george | 2020-09-12 | 684 | 1
-- out 6 | 11 | 5 | paul | 2020-02-02 | 454 | 1
-- out 7 | 12 | 6 | amy | 2020-01-12 | 252 | 1
-- out 8 | 13 | 7 | susan | 2020-05-30 | 131 | 2
-- out 9 | 14 | 7 | susan | 2020-06-06 | 252 | 1
-- you can ...
DROP TABLE indata_old;
first table :
table Name : ssc_course;
+---------------+-----------------+------------+
| ssc_course_id | ssc_course_name | qualify_id |
+---------------+-----------------+------------+
| 1 | HSC | 1 |
| 2 | Diploma | 1 |
| 3 | ITI | 1 |
+---------------+-----------------+------------+
second table :
table name :ssc_stream
+---------------+--------------------+-----------------+
| ssc_stream_id | ssc_stream_name | ssc_course_id(fk) |
+---------------+--------------------+-----------------+
| 1 | Science | 1 |
| 2 | Commers | 1 |
| 3 | Arts | 1 |
| 17 | Computer Engg | 2 |
| 18 | Mechanical Engg | 2 |
| 19 | Civil Engg | 2 |
| 20 | Electronics & TELE | 2 |
| 21 | E&TC | 2 |
+---------------+--------------------+-----------------+
third table :(master table)
table name : ssc_college
+------------+--------------+---------------+---------------+-
| ssc_clg_id | clg_login_id | ssc_stream_id | ssc_course_id |
+------------+--------------+---------------+---------------+-
| 9 | 2 | 1 | 1 |
| 10 | 2 | 1 | 1 |
| 11 | 2 | 2 | 1 |
| 12 | 2 | 2 | 1 |
| 13 | 2 | 3 | 1 |
| 14 | 2 | 3 | 1 |
| 15 | 3 | 1 | 1 |
| 16 | 3 | 1 | 1 |
| 17 | 3 | 2 | 1 |
| 18 | 3 | 2 | 1 |
| 19 | 3 | 3 | 1 |
| 20 | 3 | 3 | 1 |
| 21 | 4 | 1 | 1 |
| 22 | 4 | 1 | 1 |
| 23 | 4 | 2 | 1 |
| 24 | 4 | 2 | 1 |
| 25 | 4 | 3 | 1 |
| 26 | 4 | 3 | 1 |
| 27 | 5 | 17 | 2 |
| 28 | 5 | 17 | 2 |
| 29 | 5 | 18 | 2 |
| 30 | 5 | 18 | 2 |
| 31 | 5 | 19 | 2 |
| 32 | 5 | 19 | 2 |
| 33 | 5 | 20 | 2 |
| 34 | 5 | 20 | 2 |
| 35 | 5 | 21 | 2 |
| 36 | 5 | 21 | 2 |
| 38 | 6 | 17 | 2 |
| 39 | 6 | 17 | 2 |
| 40 | 6 | 18 | 2 |
*************************************************************
I am trying to save course,stream id's into ssc_college table.
1 course have multiple stream how can i insert this type of values
ex. course 1-diploma and this course have multiple stream like-
1.comp. engg , 2.mechanical ,3.e&tc i want to add course id and
stream id at a time of third (ssc_college) table.
and multiple stream for multiple course how i can add at a time
multiple parent and multiple child id in mysql table.
Note: stream are dependant of course table.
I have a test table
mysql> select * from test1 limit 20;
+------+------+----------------------------------+
| id | num | pass |
+------+------+----------------------------------+
| 1 | 1 | c4ca4238a0b923820dcc509a6f75849b |
| 2 | 3 | c81e728d9d4c2f636f067f89cc14862c |
| 1 | 1 | c4ca4238a0b923820dcc509a6f75849b |
| 2 | 2 | c81e728d9d4c2f636f067f89cc14862c |
| 1 | 1 | c4ca4238a0b923820dcc509a6f75849b |
| 2 | 3 | c81e728d9d4c2f636f067f89cc14862c |
| 3 | 3 | eccbc87e4b5ce2fe28308fd9f2a7baf3 |
| 4 | 6 | a87ff679a2f3e71d9181a67b7542122c |
| 5 | 7 | e4da3b7fbbce2345d7772b0674a318d5 |
| 6 | 6 | 1679091c5a880faf6fb5e6087eb1b2dc |
| 7 | 8 | 8f14e45fceea167a5a36dedd4bea2543 |
| 8 | 11 | c9f0f895fb98ab9159f51fd0297e236d |
| 9 | 10 | 45c48cce2e2d7fbdea1afc51c7c6ad26 |
| 10 | 12 | d3d9446802a44259755d38e6d163e820 |
| 11 | 12 | 6512bd43d9caa6e02c990b0a82652dca |
| 12 | 18 | c20ad4d76fe97759aa27a0c99bff6710 |
...
I want to delete the 1st,3rd and 9th row.So I use such command
delete from test1 limit 1,3,9;
But it doesn't work,is there any workaround can do this?
I need to create a log having the purchase date of an item.
Items can be owned by only one buyer at time. So, for example, if item1 was purchased by buyer2 in 2009 and after by buyer1 in 2015, then between 2009 and 2015 was owned by buyer2.
Here is my table:
+--------+------------+-----------+----------+
| id_doc | date | id_item | id_buyer |
+--------+------------+-----------+----------+
| 11 | 2016-06-07 | 1 | 4 |
| 10 | 2016-06-06 | 1 | 4 |
| 1 | 2015-11-30 | 1 | 1 |
| 9 | 2009-01-01 | 1 | 2 |
| 4 | 2001-01-12 | 1 | 2 |
| 8 | 1996-06-06 | 1 | 2 |
| 3 | 1995-05-29 | 1 | 1 |
| 2 | 1998-05-23 | 2 | 2 |
| 7 | 2014-10-10 | 3 | 2 |
| 6 | 2003-12-12 | 3 | 3 |
| 5 | 1991-01-12 | 3 | 2 |
+--------+------------+-----------+----------+
Here is a kind of table/view I need:
+------------+------------+-----------+----------+--------+
| date_from | date_to | id_item | id_buyer | id_doc |
+------------+------------+-----------+----------+--------+
| 2016-06-07 | - | 1 | 4 | 11 |
| 2016-06-06 | 2016-06-07 | 1 | 4 | 10 |
| 2015-11-30 | 2016-06-06 | 1 | 1 | 1 |
| 2009-01-01 | 2015-11-30 | 1 | 2 | 9 |
| 2001-01-12 | 2009-01-01 | 1 | 2 | 4 |
| 1996-06-06 | 2001-01-12 | 1 | 2 | 8 |
| 1995-05-29 | 1996-06-06 | 1 | 1 | 3 |
| 1998-05-23 | - | 2 | 2 | 2 |
| 2014-10-10 | - | 3 | 2 | 7 |
| 2003-12-12 | 2014-10-10 | 3 | 3 | 6 |
| 1991-01-12 | 2003-12-12 | 3 | 2 | 5 |
+------------+------------+-----------+----------+--------+
I've tried a lot with GROUP BY, GROUP_CONCAT, trying to access next record date, etc ... but I can't found out how to solve the problem.
Thanks in advance.
I finally found out the solution only for past purchases.
SELECT
main.id_doc, main.id_item, main.date AS "date_from", bi.date AS "date_to", main.id_buyer
FROM
MyTable main, MyTable bi
WHERE
bi.id_doc =
(
SELECT sub.id_doc
FROM MyTable sub
WHERE sub.id_item = main.id_item AND sub.date > main.date ORDER BY sub.date ASC LIMIT 1
);
I have three tables titled 'artist', 'album', and 'track' in MySQL, each containing information pertaining to my music library. 'artist' has the name of 4 artists, 'album' has the titles of 5 albums from those artists, and 'track' has the name of all tracks on said albums. I would like to combine the tables so the each track name has beside it the correct album title and artist name. Here are my tables:
artist
+-----------+-----------------+
| artist_id | artist_name |
+-----------+-----------------+
| 1 | Kacey Musgraves |
| 2 | The Lone Bellow |
| 3 | Ed Sheeran |
| 4 | The Civil Wars |
+-----------+-----------------+
album
+-----------+----------+-----------------------+
| artist_id | album_id | album_name |
+-----------+----------+-----------------------+
| 1 | 1 | Pageant Material |
| 2 | 1 | Then Came the Morning |
| 3 | 1 | + |
| 3 | 2 | x |
| 4 | 1 | The Civil Wars |
+-----------+----------+-----------------------+
track
+-----------+----------+----------+-------------------------------+------------+
| artist_id | album_id | track_id | track_name | track_time |
+-----------+----------+----------+-------------------------------+------------+
| 1 | 1 | 1 | Makin' Music for Money | 2.97 |
| 1 | 1 | 2 | Dime Store Cowgirl | 3.58 |
| 1 | 1 | 3 | Late to the Party | 3.63 |
| 1 | 1 | 4 | Pageant Material | 3.90 |
| 1 | 1 | 5 | This Town | 2.95 |
| 1 | 1 | 6 | Biscuits | 3.28 |
| 1 | 1 | 7 | Somebody to Love | 3.22 |
| 1 | 1 | 8 | Miserable | 3.00 |
| 1 | 1 | 9 | Die Fun | 3.47 |
| 1 | 1 | 10 | Family is Family | 2.53 |
| 1 | 1 | 11 | Good Ol' Boys Club | 3.27 |
| 1 | 1 | 12 | Cup of Tea | 2.67 |
| 1 | 1 | 13 | Fine | 7.88 |
| 2 | 1 | 1 | Then Came the Morning | 4.01 |
| 2 | 1 | 2 | Fake Roses | 3.57 |
| 2 | 1 | 3 | Marietta | 3.57 |
| 2 | 1 | 4 | Take My Love | 3.25 |
| 2 | 1 | 5 | Call to War | 3.47 |
| 2 | 1 | 6 | Watch Over Us | 3.57 |
| 2 | 1 | 7 | Diners | 4.40 |
| 2 | 1 | 8 | Heaven Don't Call Me Home | 2.60 |
| 2 | 1 | 9 | If You Don't Love Me | 3.23 |
| 2 | 1 | 10 | Telluride | 4.28 |
| 2 | 1 | 11 | To the Woods | 2.00 |
| 2 | 1 | 12 | Cold As It Is | 2.93 |
| 2 | 1 | 13 | I Let You Go | 3.42 |
| 3 | 1 | 1 | The A Team | 4.66 |
| 3 | 1 | 2 | Drunk | 4.32 |
| 3 | 1 | 3 | U.N.I. | 3.82 |
| 3 | 1 | 4 | Grade 8 | 3.00 |
| 3 | 1 | 5 | Wake Me Up | 3.83 |
| 3 | 1 | 6 | Small Bump | 4.32 |
| 3 | 1 | 7 | This | 3.27 |
| 3 | 1 | 8 | The City | 3.90 |
| 3 | 1 | 9 | Lego House | 3.08 |
| 3 | 1 | 10 | You Need Me, I Don't Need You | 3.67 |
| 3 | 1 | 11 | Kiss Me | 4.68 |
| 3 | 1 | 12 | Give Me Love | 8.77 |
| 3 | 2 | 1 | One | 4.22 |
| 3 | 2 | 2 | I'm A Mess | 4.08 |
| 3 | 2 | 3 | Sing | 3.92 |
| 3 | 2 | 4 | Don't | 3.67 |
| 3 | 2 | 5 | Nina | 3.77 |
| 3 | 2 | 6 | Photograph | 4.32 |
| 3 | 2 | 7 | Bloodstream | 5.00 |
| 3 | 2 | 8 | Tenerife Sea | 4.02 |
| 3 | 2 | 9 | Runaway | 3.42 |
| 3 | 2 | 10 | The Man | 4.17 |
| 3 | 2 | 11 | Thinking Out Loud | 4.70 |
| 3 | 2 | 12 | Afire Love | 5.23 |
| 3 | 2 | 13 | Take It BAck | 3.47 |
| 3 | 2 | 14 | Shirtsleeves | 3.17 |
| 3 | 2 | 15 | Even My Dad Does Sometimes | 3.82 |
| 3 | 2 | 16 | I See Fire | 4.98 |
| 4 | 1 | 1 | The One That Got Away | 3.55 |
| 4 | 1 | 2 | I Had Me a Girl | 3.75 |
| 4 | 1 | 3 | Same Old Same Old | 3.80 |
| 4 | 1 | 4 | Dust to Dust | 3.83 |
| 4 | 1 | 5 | Eavesdrop | 3.58 |
| 4 | 1 | 6 | Devil's Backbone | 2.48 |
| 4 | 1 | 7 | From This Valley | 3.55 |
| 4 | 1 | 8 | Tell Mama | 3.80 |
| 4 | 1 | 9 | Oh Henry | 3.55 |
| 4 | 1 | 10 | Disarm | 4.70 |
| 4 | 1 | 11 | Sacred Heart | 3.32 |
| 4 | 1 | 12 | D'Arline | 3.10 |
+-----------+----------+----------+-------------------------------+------------+
In 'track' each number under artist_id corresponds to the same numbered entry in 'artist', and the same goes for album_id and 'album'. Basically, I want to create a new table with every track in 'track', along with its respective album and artist.Any help would be appreciated!
Use JOIN in your SELECT query, like,
select * from track_name
join artist_name on track_name.artist_id = artist_name.artist_id
join album_name on track_name.album_id = album_name.album_id;
Now if you want this in new table you can insert this records in that table, or better if you want to run above query multiple time then you can create a VIEW.
MySQL Views
That sounds like a very basic join
select *
from track_name
join artist_name using (artist_id)
join album_name using (album_id)
I am writing this query by hoping there would be columns album_id and artist_id in the respective tables.
I also suggest you to change the column name track_name so to avoid conflict between table name and column name.
SELECT *
FROM `track_name` t1
LEFT JOIN `artist_name` a1 ON t1.`artist_id`=a1.`artist_id`
LEFT JOIN `album_name` a2 ON t1.`album_name`=a2.`album_name`
GROUP BY t1.`track_name`;