Selecting multiple IDs

I have this table:
CREATE TABLE avail_apps( idint(11) NOT NULL AUTO_INCREMENT, date_avdate NOT NULL, time_av time DEFAULT NULL, PRIMARY KEY (id,date_av) ) ENGINE=InnoDB AUTO_INCREMENT=8192 DEFAULT CHARSET=utf8

If I am given the date and the time I can find the id with this statement(and for the example date time shown here):

select id from avail_apps where date_av='2015-11-17' and time_av='10:00:00';

What if I am given two date times though…meaning I want to find 2 IDs from the table…

What kind of sql statement is needed for that?

SELECT id FROM avail_apps WHERE date_av = '2015-11-17' AND time_av = '10:00:00' OR date_av = '2015-11-18' AND time_av = '09:37:00'

while the above is correct and works as intended, as a general rule, whenever you mix ANDs and ORs it is wise to use parentheses –

SELECT id FROM avail_apps WHERE ( date_av = '2015-11-17' AND time_av = '10:00:00' ) OR ( date_av = '2015-11-18' AND time_av = '09:37:00' )

Ok…I got it…and it is working.
Imagine now the data being brought in the contex of a prepared statement…the following line does that:

` $stmt->bind_result($id);

There is a problem though.Since we are dealing with two IDs…how am I going to distinguish one from the other in the prepared statement.`

I found it…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.