I have two tables that have member data in them, the reason for this is that I am using Expression Engine and by default it has a standard member data table that includes Email etc. To add custom fields to my register I had to create a secondary table with additional information. I now need to do an export of all member details in a specific order.
Could anyone help me, I have an email table field from the exp_members table that I need to join to the exp_member_data table. I would like the email field added as the third field in the join, this is for an export of member details. I hope this is clear, thanks.
I don't know which fields you want to select and what there names are, but basic structure is as below:
SELECT
exp_members.field_so_and_so,
exp_members.field_so_and_so,
exp_members.email,
...,
exp_members_data.field_so_and_so,
...
FROM exp_members
INNER JOIN exp_members_data ON exp_members.email = exp_members_data.email
ORDER BY exp_members.field_so_and_so, ...
Related
I have a system used for exhibition in Website.
The exhibition data maybe from multi-data in difference table.
Like this design:
Table [ExhibitionType] used for differentiate category.
Table [ExhibitionBase] used for link extra Sub-Type table & data in different table.
My website use MySQL and PHP
Now question is I DON'T KNOW how to query it. or this design have a flaw.
EDIT 1:
I'm sorry I didn't express my intentions.
Example: I hope query a data list. first i need filter ExhibitionType like 1.
So i need create a SQL like :SELECT * FROM ExhibitionBase WHERE ExhibitionTypeId = 1
And second step i must read ExhibitionDataType and ExhibitionDataId each row data. And according to the different types of ExhibitionData data out to merge into the ExhibitionBase Sub-tables.
HOW TO DO use SQL query it.
This my question.
SELECT b.*, dt.Name, di.name
FROM ExhibitionBase AS b
JOIN ExhibitionDataType AS dt ON dt.id = b.ExhibitionDataType
JOIN ExhibitionDataId AS di ON di.id = b.ExhibitionDataId
WHERE ExhibitionTypeId = 1
Style suggestions:
Do not prefix column and table names with the database name; it clutters things. ("Exhibition")
Do not have a column name the same as its table name.
I am pretty new to MS Access and a bit at a loss. I am also not very familiar with database jargon, so bear with me.
I have a table with staff names in it (each an individual record and staffID).
I have another table with a log, each entry shows at what time a particular staffID took a particular course (course names are stored in another table).
Now I want to make a report that lists each course and the names of the people, who took it.
How do I do that?
You need to learn about database joins. Its a fundamental requirement for what you are doing.
SELECT * FROM stafftable s INNER JOIN logtable l ON l.staffID = s.staffID
will give you a virtual table listing staff details and the course they were on.
You can do this multiple times - so you say the course data is in another table
SELECT s.name As StaffName, c.name As CourseName FROM stafftables INNER JOIN (logtable l INNER JOIN coursetable c ON l.courseID = c.courseID) ON l.staffID = s.staffID
Will give you a two column table with StaffName and CourseName as the two columns. Note: Access is picky about these joins and you have to put them in brackets like this. Other databases you normally don't have to.
I think the report wizard could solve your problem.
The wizard walks you through the steps of creating a report and will allow you the opportunity to use more than one table/query in the report.
Since you are looking to group by the course, all you would need to do is tell the wizard to do that when it asks you.
This is a straight forward guide on how to use the report wizard: report wizard guide
My two MySQL tables have different information but one field is common. I am showing you the structure of two tables.
I need to show it in a single report filtering by cust_id.
i.e. Customer Id wise billing and payment report.
I tried...
SELECT * FROM billing_info as a,payment_info as b WHERE a.cust_id='1' AND b.cust_id='1' AND a.cust_id=b.cust_id
but rows are repeating.
Hope I explained this properly. Now what should I do ?
Is it possible in Crystal Report to show two tables data ?
I guess ur table structure may resulting duplicate entries.
in table payment_info instead of using the cust_id (reference of cust table), u should use id of table billing_info so that we will get more precised output for ur query.
U also get payment details agains which bill has been made.
I have some tables in databases. The table contains more than 150 columns for some custom field operations which may/may not be used by all. Instead of creating static 150 unused column fields, it can be created dynamically using add column.
Can somebody justify, which one is better? When to use dynamic, when static and why?
You can look for below normalization for maintaining custom fields, I have used in multiple web/window application successfully.
FormMasterTable
FormId, Name: this will be identifier and will be passed from Form to DB query to identify itself
datatypeMaster Table
datatypeId, datatypeName
The abobe will define all custom fields you are going to support i.e. customer can create to customize a form.
Table for Form-Customer-CustomFieldMapping say Custom Field Master Table for managing column definition and mapping with customer.
customerId, FormName/FormId, FieldName, customFieldId, datatypeId(FK:datatypeMaster), length ....
Next step is to create all tables to store all datatypes defined in datatypeMaster table i.e. one table for each datatype, some of the examples I can think of....
Custom field detail table for numeric say CustomNumberFields
customFieldId FieldValue(numeric(max))
Custom field detail table for string say CustomTextFields
customFieldId FieldValue(varchar(max))
Custom field detail table for Dates say CustomDateFields
customFieldId FieldValue(datetime)
and so on....
Now you can use all in one query with Inner Join to get all custom columns of a customer.
Sample Query to get customfields fields
select MP.FieldName, CFN.FieldValue from Form-Customer-CustomFieldMapping MP
JOIN CustomNumberFields CFN on MP.CustomFieldId and CFN.CustomFieldId where formId=<<paramformId>> and customerId=<<paramcustomerId>>
UNION
select MP.FieldName, CFN.FieldValue from Form-Customer-CustomFieldMapping MP
JOIN CustomTextFields CFN on MP.CustomFieldId and CFN.CustomFieldId where formId=<<paramformId>> and customerId=<<paramcustomerId>>
UNION
select MP.FieldName, CFN.FieldValue from Form-Customer-CustomFieldMapping MP
JOIN CustomDateFields CFN on MP.CustomFieldId and CFN.CustomFieldId where formId=<<paramformId>> and customerId=<<paramcustomerId>>
I am trying to create a table that shows treatment information about patients (though I just wondered if would be better as a query) at a fictional hospital. The idea is that one row of this could be used to print an information sheet for the attending nurse(s).
I would like to make the attending_doctor column contain the name that corresponds with the employee_id.
|Patient_ID|Employee_ID|Attending_Doctor|Condition|Treatment|future_surgery|
Would appreciate any help. Thank you!
Just use a join in your query rather than have the employee name in 2 tables (which would mean updating in more than one location if they change name etc). For the sake of an example, this also gets the patients name from a 3rd table named patients.
eg
SELECT table1.*, employees.name, patients.name
FROM table1
LEFT JOIN employees ON employees.id = table1.employeeId
LEFT JOIN patients ON patients.id = table1.patientsId
Don't use directly this table, but build a view that contains the data you need. Then you can get the data from the view like it was a table.
Basically what you need is to have data in three tables. One table for patients, one table for for employees and one for the reports. Table with reports should contain only the employee_ID. Then you can either build a direct query over these three tables or build a view that will hide the complicated query.