Hello readers,

I was wondering if there is a feature in MySQL that allows us to insert a row with only some values from another table. INSERT...SELECT syntax helps to insert multiple rows and it seems not to allow any constant values.

Let's clarify the case with an example.

I have a table of concerts and different pricing classes. The table structure of this price class table is like following:
- concertid
- code
- name
- price


Then there is another table having information of bookings. Its structire is following:
- id
- concertid
- priceclasscode
- price


Normally I would just make a relation query that joins a price from the price class table. But as there is a need to customize the price in some cases, I decided to make another price field to the booking table. When a new booking is made, I should copy the default price to the booking table. Now I'm looking a quick way to it. Like this:

INSERT INTO bookings SET concertid = 1, priceclasscode="A", price = (SELECT price FROM priceclasses WHERE concertid = 1 AND code="A");

Any possibilities? Or should I just make two queries in my application?

Thanks for tips and trics! =)

Ville Mattila
Ikaalinen, Finland

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to