Ronel Posted March 16, 2022 Share Posted March 16, 2022 SELECT `itemname`,`poqty` FROM `history` WHERE action = 'Added qty' SELECT `received_qty` FROM `history` WHERE action = 'Stock Received' SELECT `outgoing_qty` FROM `history` WHERE action = 'Outgoing Record Recorded' How do i query these lines in one single line someone help please?? Below is my image for database history. Quote Link to comment https://forums.phpfreaks.com/topic/314603-how-do-i-query-these-lines-in-one-single-line-someone-help-please/ Share on other sites More sharing options...
requinix Posted March 16, 2022 Share Posted March 16, 2022 Have you tried a query that lists all the columns and requires any of the conditions? Quote Link to comment https://forums.phpfreaks.com/topic/314603-how-do-i-query-these-lines-in-one-single-line-someone-help-please/#findComment-1594406 Share on other sites More sharing options...
ginerjm Posted March 16, 2022 Share Posted March 16, 2022 What requinix is possibly saying is to use a WHERE clause that includes all of your 'ifs' in one query statement. You may want to use an ORDER BY clause at the same time. Suh as: Where fld='xxx' or fld == 'yyy' or fld ='zzz' order by fld Quote Link to comment https://forums.phpfreaks.com/topic/314603-how-do-i-query-these-lines-in-one-single-line-someone-help-please/#findComment-1594408 Share on other sites More sharing options...
Ronel Posted March 16, 2022 Author Share Posted March 16, 2022 yes below image is what i got after running the query in my database. But how do put the itemname row on same line ? it has several entries with same itemnames? Quote Link to comment https://forums.phpfreaks.com/topic/314603-how-do-i-query-these-lines-in-one-single-line-someone-help-please/#findComment-1594409 Share on other sites More sharing options...
Phi11W Posted March 16, 2022 Share Posted March 16, 2022 13 minutes ago, Ronel said: it has several entries with same itemnames? Well, yes it does, because that's what's in your data! What you're missing is the action that caused each row to appear in your results. Include the action column and your data should make a little more sense. What are you trying to achieve? Calculation of total stock levels based on actions against each item? For that you'd want something like this: select id , sum( case action when 'Added Qty' then poqty when 'Stock Received' then received_qty when 'Outgoing Record Recorded' then - outgoing_qty /* negate value to deduct from total */ end ) qty from table1 group by id order by action ; Bear in mind that ordering by a text field (whose values might change over time) could give you headaches. It might be better to codify these values (into a "Lookup" Table) so that you can sequence them reliably. Regards, Phill W. Quote Link to comment https://forums.phpfreaks.com/topic/314603-how-do-i-query-these-lines-in-one-single-line-someone-help-please/#findComment-1594410 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.