Ronel Posted March 17, 2022 Share Posted March 17, 2022 SELECT * FROM History WHERE entrydate BETWEEN 'from_date' AND 'to_date'; SELECT `id`,`itemname`, `poqty`, `entrydate`,`date_encode` FROM history WHERE action = 'Outgoing Record Recorded' AND interface = 'Outgoing Stock'; Quote Link to comment https://forums.phpfreaks.com/topic/314606-how-do-i-join-these-two-both-and-fetch-data-in-my-result-someone-help-please/ Share on other sites More sharing options...
mac_gyver Posted March 17, 2022 Share Posted March 17, 2022 you could always make an attempt and observe the result to see if your query does what you want. SELECT the columns you want FROM your table WHERE all the where conditions here... Quote Link to comment https://forums.phpfreaks.com/topic/314606-how-do-i-join-these-two-both-and-fetch-data-in-my-result-someone-help-please/#findComment-1594416 Share on other sites More sharing options...
Ronel Posted March 17, 2022 Author Share Posted March 17, 2022 how do i put several WHERE conditions together it is not working or may be i am not aware of other logic please show some light if you can? Quote Link to comment https://forums.phpfreaks.com/topic/314606-how-do-i-join-these-two-both-and-fetch-data-in-my-result-someone-help-please/#findComment-1594417 Share on other sites More sharing options...
mac_gyver Posted March 17, 2022 Share Posted March 17, 2022 (edited) repeating things that you have seen is not learning. it is just you typing something at your location that someone else has told you to do. you must actually look at and learn what the words and syntax that you are using mean, i.e. internalize the information. there are a huge amount of examples for all the fundamental programming operations to be found on the internet. if you didn't do a web search for sql where with multiple conditions before starting this thread, why not? the second query has two conditions in the WHERE clause, with a logical AND operator between them (must include a AND b.) how did you arrive at that? what did you learn by doing that? to add the third column BETWEEN ... AND ... condition, you would just AND it with the rest of the WHERE conditions (must include a AND b AND c.) Edited March 17, 2022 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/314606-how-do-i-join-these-two-both-and-fetch-data-in-my-result-someone-help-please/#findComment-1594418 Share on other sites More sharing options...
ginerjm Posted March 17, 2022 Share Posted March 17, 2022 Have you used google to find a mysql source (aka manual) that can teach you about writing a select query? BTW -- it is not a good practice to use the asterisk in your select queries. Always specify the column names you want to select. Makes it easier to edit later on when you want to make adjustments of if you are looking at someone else's code who hasn't learned to not use it. Quote Link to comment https://forums.phpfreaks.com/topic/314606-how-do-i-join-these-two-both-and-fetch-data-in-my-result-someone-help-please/#findComment-1594419 Share on other sites More sharing options...
ginerjm Posted March 17, 2022 Share Posted March 17, 2022 Here's a link (that I did a google search for) that may give you some better idea of how to write a query. https://www.mysqltutorial.org/mysql-select-statement-query-data.aspx Quote Link to comment https://forums.phpfreaks.com/topic/314606-how-do-i-join-these-two-both-and-fetch-data-in-my-result-someone-help-please/#findComment-1594420 Share on other sites More sharing options...
gizmola Posted March 19, 2022 Share Posted March 19, 2022 So it appears that you require at least one variable here. Are you using PHP? Where is your PHP query code, because you have to be using either PDO or MySQLi, or some wrapper of one of those like DBAL. I'd expect something like this (PDO Example): $query = "SELECT * FROM History WHERE entrydate BETWEEN ? AND ? AND action = 'Outgoing Record Recorded' AND interface = 'Outgoing Stock'"; $stmt = $pdo->prepare($query); $stmt->execute([$fromDate, $toDate]); $user = $stmt->fetch(); Make sure you know when to use a single quote ( ' ) and when to use a backtick ( ` ) in a mysql query. Backticks go around mysql table and column names. They are optional, but may be needed if you used a mysql keyword as a table or column name. Most of the time, you don't need to use backticks. Quote Link to comment https://forums.phpfreaks.com/topic/314606-how-do-i-join-these-two-both-and-fetch-data-in-my-result-someone-help-please/#findComment-1594432 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.