Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL: Select all rows containing the ID
    primarykey
    data
    text
    <p>I'm trying to write a MySQL query which should select rows from two different tables. I have made a different amount of queries but they all take pretty long time before they return the result (> 0.6 seconds). I want to have a even faster response.</p> <p>The situation is:</p> <pre><code>CREATE TABLE `classes` ( id int(99) auto_increment primary key, status INT(1) ) CREATE TABLE `classes_names` ( id int(99) auto_increment primary key, class_id int(99), name VARCHAR(255) ) </code></pre> <p>Lets say you should get all the names in the class, except the one you're searching for. For example, my name is "John Doe", so we search for my name like this:</p> <pre><code>SELECT classes_names.`id` FROM `classes_names` INNER JOIN `classes` ON `status` = 1 WHERE `name`='John Doe' </code></pre> <p>In this query, my name will be returned together with my class ID. The thing is, I want the "class members" to be returned exluding myself. So lets say we have this table:</p> <pre><code>+------+----------+ | id | status | +------+----------+ | 1 | 1 | | 2 | 1 | +------+----------+ +------+----------+---------------+----------+ | id | class_id | name | +------+----------+--------+-----------------+ | 1 | 1 | John Doe | | 2 | 1 | Alexandra Fito | | 3 | 2 | Rico Hasti | | 4 | 1 | Lady Gaga | +------+----------+--------------------------+ </code></pre> <p>The query I want to do as "described" with words: <code>SELECT class_names.id WHERE SAME CLASS HAS NAME 'John Doe'.</code> The returned rows should be ALL members in the class - without the searched name... So the result I should be expecting is:</p> <pre><code>+------+----------+---------------+----------+ | id | class_id | name | +------+----------+--------+-----------------+ | 2 | 1 | Alexandra Fito | | 4 | 1 | Lady Gaga | +------+----------+--------------------------+ </code></pre> <p>Sooo... Anyone wants to give it a shot? Go for it!</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.
    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