I want to combine the following queries into a single query:
SELECT val FROM resource WHERE facet="all" and urlId="1234"
SELECT val FROM resource WHERE facet="your" and urlId="1234"
SELECT val FROM resource WHERE facet="base" and urlId="1234"
Oh — there are multiple “facets” for each urlId. But only one row per “facet”. This table was setup by somebody else. We are migrating away. Obviously it would be better to have a column for each “facet” and a single row, but it’s too late for that.
I can do this with multiple queries, but would like to have a faster/better solution.
<pre>
mysql> describe resource;
+-------------+-------------------------------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------------------------------+------+-----+-------------------+-----------------------------+
| resId | int(11) unsigned | NO | PRI | NULL | auto_increment |
| urlId | int(11) | NO | MUL | NULL | |
| sectionId | int(3) | YES | | NULL | |
| mode | enum('archive','live','edit','dev') | NO | | edit | |
| facet | varchar(50) | NO | MUL | NULL | |
| typeId | int(1) | NO | | 1 | |
| val | mediumtext | NO | | NULL | |
| itemOrder | tinyint(2) | NO | | 1 | |
| editorId | varchar(30) | NO | | NULL | |
| created | datetime | NO | | NULL | |
| lastUpdated | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------------+-------------------------------------+------+-----+-------------------+-----------------------------+
11 rows in set (0.05 sec)
</pre>
Remember: in soviet russia, SQL queries you.
This is my preferred method which will use your indexes: