Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>can you provide some table schematics to work with? i also don't see any <code>GROUP BY</code> in your query. i assume you want to <code>GROUP BY so_alcohol.id</code>? if you want to group only by <code>so_alcohol.id</code> you will have to use an aggregate function on the remaining columns like <code>max(so_alcohol.name) as name</code>. <a href="https://stackoverflow.com/questions/9373395/getting-info-from-two-mysql-tables/9374416#9374416">further reading about max()</a></p> <p>your second problem is really none. you can join on any available column even if you don't decide to have it in the result. example: </p> <pre><code>SELECT MAX(customer.email) AS email, MAX(customer.name) AS name, GROUP_CONCAT(address.country) AS countries FROM customer JOIN /* customer.address_id is not in the SELECT-clause, but you can still use the column to join */ address ON customer.address_id = address.id GROUP BY customer.id </code></pre> <p>if you are thinking about splitting the value of firstName into single names afterwards, don't. have mysql produce one user per row and do the grouping in PHP while outputting. </p> <p>Edit1: Example on GROUP BY</p> <p>TABLE product</p> <pre><code>id name 1 Product1 2 Product2 </code></pre> <p>TABLE rating</p> <pre><code>rating_id product_id 1 1 2 1 3 2 </code></pre> <p>Join </p> <pre><code>SELECT * FROM product JOIN rating ON product.id = rating.product_id </code></pre> <p>outputs</p> <pre><code>id name rating_id product_id 1 Product1 1 1 1 Product1 2 1 2 Product2 3 2 </code></pre> <p>adding a <code>GROUP BY id</code>-clause</p> <pre><code>SELECT id, MAX(name) AS name, COUNT(rating_id) AS rating_count FROM product JOIN rating ON product.id = rating.product_id GROUP BY id </code></pre> <p>will put all tuples that have the same value in the column <code>id</code> into one group:</p> <pre><code>id name rating_count 1 Product1 2 2 Product2 1 </code></pre> <p>you are not allowed to select columns in your result, which you do not group by or use aggregate functions on. but mysql will let this slip and provide you with a reasonable result anyway.</p> <p>hope that mini-tutorial works. if not i suggest to get to know SQL better before you continue to use codeigniter. if you don't understand what codeigniter does behind the curtains, you will not be able to control your output. </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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