Jump to content

Help with MySQL Views


jbwebdesign

Recommended Posts

Hello, I was speaking with stephan and I asked him how can I link 2 different tables in MySQL.....I was told that creating "views" is the easiest way to go about doing this. At first i didn't have any idea what "views" were but now after googling mysql views i learned a bit about them.

 

I still do not know how to use the views and I would really appreciate it if anyone can help out.

 

I have a table that contains users and i want to create another table that will allow me to keep a record of the users sales and what they sold as well as what dates they sold it.

 

Please help me out with mysql Views

Link to comment
Share on other sites

Shall we say "Views are virtual tables".

 

It is best to segregate your tables. So you have a customer table, a sales table, a product table...

 

This can be complicated, so a view is a form of table you create with what you need.

 

Your customer table may have customer business name, contact name, telelphone, zip, address, country, birthdate etc. The product table has product names, numbers, prices, manufacturer...

 

What you want access to is bits and pieces of that info... so you create a view, a new quasi table with just that info you want. Customer name, amount, sales cost, etc. all in one place while the more detailed info is still in separate tables.

 

I am really not sure if this is "Easier" or not. Guess it is more personal preference when dealing with small sites. Once you are used to it I could get the same info specific to the request in a couple of minutes using "Joins" and it really makes little difference if I query a view or a Join.

 

Here we use mostly Joins, my old department used views... we had databases with more views saved by different people than we did the tables they drew from. Here at retirement, I deal in SQL queries that cross multiple schemas with multiple tables...

 

The larger the site the less I would use views but for the info that is regularly needed... of course then there are stored procedures and packages etc. that you can choose from in real SQL.

 

I am not sure how limited MySQL is, but if you become good with SQL then Joins are fine, if you do not expect to use it much and this is info you need often, then yea, views would likely be the way to go.

 

Just remember to separate your info into tables... in minute detail... then make the view by joining the tables and pulling out the info you need most.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...