Note that there are some explanatory texts on larger screens.

plurals
  1. POJust can't seem to get mysql query correct
    primarykey
    data
    text
    <p>I am trying to get results that i know are there but just can't seem to get the query right. I am using the following:</p> <pre><code>SELECT * FROM carpets AS c INNER JOIN carpet_relations AS r ON c.id = r.carpet_id WHERE c.active = '1' AND **((r.relation_type = '5') AND (r.related_id = '1' ))** *AND* ((r.relation_type = '4') AND (r.related_id = '1')) AND (c.width_feet BETWEEN '0' AND '17') AND (c.width_inches BETWEEN '0' AND '11') AND (c.height_feet BETWEEN '0' AND '29') AND (c.height_inches BETWEEN '0' AND '11') ORDER BY c.item_no </code></pre> <p>as you can see i am trying get results that have two matching fields in a second table if i change the and that is in italics to an or i get results but it is results for both i need the results that are in the set prior to the and which is bold</p> <p>so it would be something like:</p> <p>list that has relation type 5 and 4</p> <p>keep in mind that related id could be different for both there are three colums carpet_id,related_id,relation_type</p> <p>thanks for any help</p> <p>c_categories Column Type Null Default Comments id int(11) No<br> title varchar(250) No<br> active int(11) No<br> weight int(11) No<br> template_id int(11) No </p> <p>c_sizes Column Type Null Default Comments id int(11) No<br> title varchar(250) No<br> active int(11) No<br> weight int(11) No<br> template_id int(11) No</p> <p>carpet_relations</p> <p>Column Type Null Default Comments</p> <p>carpet_id int(11) No &lt;------ signifies which carpet the relationship is with</p> <p>related_id int(11) No &lt;------ the id of the c_size or c_categories to use</p> <p>relation_type int(11) No &lt;------ signifies which table either c_sizes or c_categories</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload