fabiangarga Posted August 1, 2013 Share Posted August 1, 2013 Hi guys, im new on this forum.I have a little problem with a SQL query, im trying to get a query feedback but im lost.I got 2 tablesTable 1:ID_product , priceThen have a second tableTable 2:ID, DescriptionOn the second table, the column description contains a string, and somewhere in the string it has this text "{price = A}", the price is the same from the table 1.What im trying to figure out, is how i can display ID_product, price,from table 1, and also the ID from the row that contains the same price as the table 1 in the string.Im not sure if im clear, im not really good writing and less in english.I will apreciate the help, thanks! Quote Link to comment Share on other sites More sharing options...
requinix Posted August 1, 2013 Share Posted August 1, 2013 Does that "=A" mean anything? Is it more than just inserting the price in at the "{price}"? How do you relate the two tables? Does table 2's ID pair with table 1's ID_product? Any reason why the description is in its own separate table when they sound like they match up with individual products? Quote Link to comment Share on other sites More sharing options...
fabiangarga Posted August 1, 2013 Author Share Posted August 1, 2013 Im working with a joomla data base, one table is from a e-commerce plugin and the other is from the article description wich contains in some part the price of the product.I dont need to insert, i need to select and get a feedback with the id_product, ID of the article wich contains the price of the product on the description and the price.The price, and id of the product i can get it easly from the table of the e-commerce plugin, but i need to get on the same feedback the ID of the article wich contains the price.This is an example of the 2 tables The feed will be something like this: Quote Link to comment Share on other sites More sharing options...
requinix Posted August 1, 2013 Share Posted August 1, 2013 So no two products with the same price, huh? Can you alter the ID/Description table to include a column actually dedicated to the price, rather than stuffing it in a place it doesn't belong? Quote Link to comment Share on other sites More sharing options...
fabiangarga Posted August 1, 2013 Author Share Posted August 1, 2013 My bad, in the description also i have somewhere in the test a string with {id="product_id"} and this one is unique, what could happen is that one article on the description has more than one product_id, but i think it will not screw my future php code.I cant alter the table, because it will mess up the e-commerce, i dont know if this could be done with mysql, probably yes, but it will require a lvl of mysql that i dont have, i was thinking solve it using php and , like having 2 multi arrays with each tables, and then with php, serch into the second table and make a third array with the data i need.If i could make it in one sql query it will be fantastic. Quote Link to comment Share on other sites More sharing options...
requinix Posted August 1, 2013 Share Posted August 1, 2013 I would not try to do this in SQL. It's possible, but disgustingly ugly. Fall back to using PHP code. You'd have to strip out those stupid tag things anyways so you can fetch the related data while you do. Quote Link to comment Share on other sites More sharing options...
fabiangarga Posted August 1, 2013 Author Share Posted August 1, 2013 It will be ugly c:I'm gonna try doing on php, will post the answer later.Thanks! Quote Link to comment Share on other sites More sharing options...
fabiangarga Posted August 7, 2013 Author Share Posted August 7, 2013 I asked to a person that knows a lot more than me and found me a solution to my problem. I dont know how big is this forum comunity, or if mysql is not the most popular topic, but thanks to requinix for the answers. The query was solved using CONCAT SELECT pc.id, p.product_id, p.price, pc.Description FROM table1 p, table2 pc WHERE pc.Description like concat('%price=', p.product_id, '%') Hope that someone found this answer useful Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.