The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Creating a view from multiple tables
tudsy
post Aug 5 2018, 11:32 PM
Post #1


Advanced Member
****

Group: Members
Posts: 246
Joined: 30-September 14
Member No.: 21,611



Hi

I have 4 tables, CustomersArt,Customers,subscribers and emailcomm.

My question is, how do i create a view from these 4 tables with the column email ?

I have done a view from one table (see below):

$query = "CREATE VIEW ecovib2d AS SELECT email FROM CustomersArt";


Any help will be appreciated.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
CharlesEF
post Sep 7 2018, 12:40 AM
Post #2


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



That doesn't help much. Customers contains no data and CustomersArt contains 1 row. Since there is no matching row in Customers nothing is returned.
Let me try to explain what the query does. Customers is considered the header table while CustomersArt is considered the detail table. The query will return all rows in the header table. When a matching row is found in the detail table then the detail row data is returned along with the header row data. Since the table Customers is empty no data is returned.

Exactly what do you want the query to do?

This post has been edited by CharlesEF: Sep 7 2018, 01:06 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
tudsy
post Sep 7 2018, 01:05 AM
Post #3


Advanced Member
****

Group: Members
Posts: 246
Joined: 30-September 14
Member No.: 21,611



QUOTE(CharlesEF @ Sep 7 2018, 03:10 PM) *

That doesn't help much. Customers contains no data and CustomersArt contains 1 row. Since there is no matching row in Customers nothing is returned.

Exactly what do you want the query to do?


Thanks for that.

I want the visitor to look at his/her data (the whole database) using his/her email address.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Sep 7 2018, 01:48 AM
Post #4


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



QUOTE(tudsy @ Sep 7 2018, 01:05 AM) *

I want the visitor to look at his/her data (the whole database) using his/her email address.
Then why have you been using ItemId in the ON condition? That can be fixed. One thing I don't understand, when you say visitor do you mean a customer? If yes then why was there no data in the Customers table? I mean, there was 1 row of data in CustomersArt which telles me a customer bought some art from you. Then why wasn't there a customer in the Customers table? And, how does emailcomm and subscribers tie in to the Customers table? Maybe you need a better database layout design, I mean you do seem to duplicate data between the tables.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic
tudsy   Creating a view from multiple tables   Aug 5 2018, 11:32 PM
CharlesEF   You need to look in to INNER JOIN or OUTER JOIN to...   Aug 6 2018, 01:42 PM
tudsy   You need to look in to INNER JOIN or OUTER JOIN t...   Aug 6 2018, 01:57 PM
CharlesEF   You still don't tell me what columns you want ...   Aug 6 2018, 02:07 PM
tudsy   You still don't tell me what columns you want...   Aug 6 2018, 11:30 PM
tudsy   Hi A solution: “CREATE VIEW ecovib2d AS SELECT...   Aug 10 2018, 03:55 AM
CharlesEF   No. You're not joining any tables. Here is a...   Aug 10 2018, 12:13 PM
CharlesEF   You should start by joining just 1 table. I haven...   Aug 10 2018, 03:31 PM
CharlesEF   Ok, here is a hint. Since you never said which co...   Aug 11 2018, 12:21 PM
tudsy   Ok, here is a hint. Since you never said which c...   Aug 11 2018, 10:38 PM
CharlesEF   I don't think so, you need to change the ON pa...   Aug 12 2018, 12:16 AM
tudsy   I don't think so, you need to change the ON p...   Aug 14 2018, 08:21 PM
tudsy   I don't think so, you need to change the ON ...   Aug 14 2018, 09:53 PM
CharlesEF   Just in case, your error is here: WHERE email =...   Aug 15 2018, 01:06 AM
CharlesEF   Correction: Since the entire query should be enclo...   Aug 15 2018, 12:12 PM
tudsy   Hi I have another problem. Here is a query: ...   Aug 15 2018, 11:27 PM
CharlesEF   I don't see anything wrong, as far as syntax. ...   Aug 16 2018, 12:13 AM
tudsy   I don't see anything wrong, as far as syntax....   Aug 20 2018, 08:11 PM
CharlesEF   I don't see anything wrong with the syntax. A...   Aug 21 2018, 02:43 PM
tudsy   I don't see anything wrong with the syntax. ...   Aug 26 2018, 12:48 AM
CharlesEF   $query = "CREATE VIEW ecovib2d AS ...   Aug 26 2018, 02:39 AM
tudsy   Hi Thanks for that. I renamed the column names w...   Sep 4 2018, 11:49 PM
CharlesEF   $query ="SELECT Customers.Customersitem...   Sep 5 2018, 12:11 AM
tudsy   $query ="SELECT Customers.Customersite...   Sep 5 2018, 12:15 AM
CharlesEF   Create a new PHP script and place this code in it....   Sep 6 2018, 12:24 AM
tudsy   Create a new PHP script and place this code in it...   Sep 6 2018, 09:54 PM
CharlesEF   That tells me the script did run but returned no r...   Sep 6 2018, 10:26 PM
tudsy   That tells me the script did run but returned no ...   Sep 6 2018, 10:59 PM
tudsy   That tells me the script did run but returned no ...   Sep 6 2018, 10:59 PM
CharlesEF   That doesn't help much. Customers contains no...   Sep 7 2018, 12:40 AM
tudsy   That doesn't help much. Customers contains n...   Sep 7 2018, 01:05 AM
CharlesEF   I want the visitor to look at his/her data (the w...   Sep 7 2018, 01:48 AM
CharlesEF   I want to add that if you are happy with your data...   Sep 7 2018, 05:40 PM
tudsy   I want to add that if you are happy with your dat...   Sep 7 2018, 08:50 PM
CharlesEF   Results: Viewing your data from ECOVIB2DS databas...   Sep 7 2018, 09:08 PM
tudsy   Results: Viewing your data from ECOVIB2DS databa...   Sep 7 2018, 10:38 PM
tudsy   [quote name='CharlesEF' post='136182' date='Sep 8...   Sep 7 2018, 10:47 PM
CharlesEF   Telling me about an error but now showing the quer...   Sep 7 2018, 11:46 PM


Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 23rd April 2024 - 07:10 AM