Jump to content

how do I join these two both and fetch data in my result someone help please?


Ronel
 Share

Recommended Posts

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';

 

Link to comment
Share on other sites

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 by mac_gyver
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.  

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.