Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You've not shown us the schema of your table; that makes it harder than it might be to help you.</p> <p>If you are seeking to get <code>car1</code> column or <code>car2</code> column or ... then there are at least two problems:</p> <ol> <li>Your table is incorrectly designed.</li> <li>You cannot build up the name of a column (or table) as part of the query.</li> </ol> <p>You should put the information about each of a customer's cars in a separate table from the information about the customer. Thus, the information that the customer's name is 'Joe' belongs in one table; the fact that he drives a Lamborghini should be recorded in a separate table. There might be multiple records in the table of cars for each customer.</p> <p>You'd also need to join the two tables; your syntactically incorrect query doesn't attempt to do that.</p> <hr> <p>You have two tables with columns:</p> <ul> <li><p><strong>Customers</strong>: customer, type, ...</p></li> <li><p><strong>Customers_Cars</strong>: main_vehicle, car1, car2, car3</p></li> </ul> <p>You probably have, but haven't shown, some sort of 'customer' column in <code>Customers_Cars</code>. In fact, you should probably have a 'Customer ID' column in each table. Further, the <code>Customers_Cars</code> table should be just:</p> <ul> <li><strong>Customers_Cars</strong>: CustomerID, CarNum, CarInfo, MainVehicle</li> </ul> <p>In this, I'm assuming <code>MainVehicle</code> is a boolean flag, and that there is one entry tagged true per customer.</p> <p>Your SELECT statement then becomes:</p> <pre><code>SELECT U.*, C.CarInfo FROM Customers AS U JOIN Customers_Cars AS C ON C.CustomerID = U.CustomerID WHERE C.MainVehicle = TRUE AND U.Customer = 'Joe' AND U.Type = 'CoolCustomer'; </code></pre>
    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.
    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